ID:174264
 
I'm almost done making my guild system, but I'd like to create a 'List Guild' verb. How would I go about doing this?
//edit //


I figured most of it out, but I'd show how many people are in it. This is what I got...
        List_Guilds()
var/t
for(t in guilds)
src << "[t][guilds[t]]"


There honestly isn't enough information to show you how to do it correctly... but i'll assume your guilds verb is "guild"

List_Guilds()
var/t
for(t in guilds)
src << "[t][guilds[t]]"

var/t = nothing, and in guilds makes it think guilds is a list of a kind, which I assume it isnt.

So instead of this(once again assuming guilds is your var, and you used src.guild = "Guild Name" ..)


Mob/verb()
List_Guilds()
for(var/mobs/P in world)
src << "[P.name] [P.guild]
That loops through all the mobs in world, and displays their name, and guild.

James
In response to SSJ2GohanDBGT
SSJ2GohanDBGT wrote:
So instead of this(once again assuming guilds is your var, and you used src.guild = "Guild Name" ..)


Mob/verb()
List_Guilds()
for(var/mobs/P in world)
src << "[P.name] [P.guild]
That loops through all the mobs in world, and displays their name, and guild.

This is a non-solution, though. It's redundant information and it's not at all what he's looking for: He wants a list of guilds, not a list of players.

Besides, not only is the approach wrong, but you've got at least 4 serious syntax errors in there.

Lummox JR
In response to Lummox JR
List_Guilds()
usr << "Guilds:"
for(var/t in guilds)
usr << "- [t]"

If you want them numbered.

List_Guilds()
var/n=1
usr << "Guilds:"
for(var/t in guilds)
usr << "[n]. [t]"
n++
Rocker121 wrote:
I'm almost done making my guild system, but I'd like to create a 'List Guild' verb. How would I go about doing this?
//edit //


I figured most of it out, but I'd show how many people are in it. This is what I got...
List_Guilds()
var/t
for(t in guilds)
src << "[t][guilds[t]]"

Well, some information is missing here, like what's in the guilds list: Are they just names, or are they lists of players, or are they datums (the best solution) like /guild? How are your guilds organized?

One thing I can tell you off the bat is that when you loop through using for(t in guilds), t is not a list index; it's the actual item in the list. Therefore guilds[t] would be a value associated with that.

Here's a simple example of how you'd handle this using the datum approach:
var/list/guilds = list()

guild
var/name
var/list/members

New(newname, mob/founder)
name = newname
members = list(founder)
founder.guild = src
founder << "<b>You form [name].</b>"
guilds += src

Del()
for(var/mob/M in members)
M << "<b>[name] disbands.</b>"
M.guild = null
guilds -= src
..()

proc/Join(mob/M)
if(!M || M.guild == src) return
if(M.guild) M.guild.Leave(M)
M.guild = src
members += M
members << "<b>[M.name] joins [name].</b>"

proc/Leave(mob/M)
if(!M || M.guild != src) return
M.guild = null
if(members.len <= 1) del(src)
members << "<b>[M.name] leaves [name].</b>"
members -= M

mob
var/guild/guild

verb/List_Guilds()
for(var/guild/G in guilds)
usr << "<b>[G.name]:</b> [G.members.len] member\s"

Lummox JR
In response to Lummox JR
Lummox, that's exactly what I was looking for =D. Thanks a bunch.