ID:176634
 
How would you make a clan verb that generates a list that is a clan name for clan creation and adds to the list when the founder adds new players into the clan.
Drafonis wrote:
How would you make a clan verb that generates a list that is a clan name for clan creation and adds to the list when the founder adds new players into the clan.

You can add to a list just like you do a number or a string:<code> var/list/L = list() L += "Red" L += "Blue" L += "Grey" L += list("Yellow","Purple","Grey") </code>

You can also use the list procedures Add() and Remove():<code> var/list/L = list("Green","Purple") L.Add("Red") L.Remove("Purple") </code>

Alathon
In response to Alathon
Alathon wrote:
Drafonis wrote:
How would you make a clan verb that generates a list that is a clan name for clan creation and adds to the list when the founder adds new players into the clan.

You can add to a list just like you do a number or a string:<code> > > var/list/L = list() > > L += "Red" > L += "Blue" > L += "Grey" > L += list("Yellow","Purple","Grey") > > </code>

You can also use the list procedures Add() and Remove():<code> > > var/list/L = list("Green","Purple") > > L.Add("Red") > L.Remove("Purple") > </code>

Alathon

That helps me with my second question, but not my first question.
In response to Drafonis
Drafonis wrote:
That helps me with my second question, but not my first question.

Had you been more clear I would've tried both questions :)

"How would you make a clan verb that generates a list that is a clan name " is very vague and I can't really find out what your trying to do. Please explain what it is your trying to achieve thoroughly :)

Alathon
In response to Alathon
I'll explain what I mean. I want the list name to be the name of the clan. For example, if I made a clan named "Warriors of Darkness", the name of the list would be warriorsofdarkness.
In response to Drafonis
Why not use a variable eg.
var/name

name = "Warriors of Darkness"

Then to view the name:

usr << "The name of the clan is [name]"

A also have a question about lists:

How do you output a list?


In response to Hazman
Hazman wrote:
Why not use a variable eg.
var/name

name = "Warriors of Darkness"

Then to view the name:

usr << "The name of the clan is [name]"

A also have a question about lists:

How do you output a list?


Sending a list as output directly will result in /list, because it is a type. You need to loop through the contents of the list. There's a few ways to do it, but heres a nice and easy one:

for(var/A in list) world << A

Another way to do it:

for(var/a=1,a<=length(list),a++) world << list[a]

That uses list indexes to display an item in the list(item #a of list 'list')

The blue book has a lot of nice info on handling lists, as does the guide/reference/faq(?).


As for your question Drafonis, there is no way to dynamically name a list like that, because DM needs a variable name to refer something by thats constant throughout the program. Mayby im missunderstanding you, though. What do you want to achieve with the list?

Alathon
In response to Alathon
You could sort of name the list (as always, I don't know if this would work but hey, life's just like that):
datum //Datum instead of straight variable so that it can be called by anything.
Clan
var/name = members
var/members = list() //rename members to what you want.

//Then do something like

proc/Callist(list as text)
for(var/A,datum/Clan) // *
if(list == A.name)
src << "Name of Clan: [A.name]"
src << "Members:"
for(var/B in list)
src << B

You might have to modify the FOR statment marked by a commented * though.
In response to Hazman
You'd have to make a new instance of datum/Clan for that to work, and refer to that instance. Remember that the definition is different from the declaration; just because something is defined, doesn't mean it exists. I could define a "blue elephant" as being "a type of elephant that is blue", but that doesn't mean it exists. :-)

Then find the clan you want by looping through all instances of datum/Clan in the world, and choosing the one which has the name (or member) you want to display. Take that clan, output its name and members, and hey presto.
In response to Crispy
Or, alternatively, if you don't want to stupidly waste precious CPU power, you could change each of the clan datum's <code>tag</code> variable, and then use <code>locate(tag)</code> to find the clan. EX: <code>locate("Knights who say \"Nee!\"")</code> would return the clan of the knights who say "nee!", for all your shrubbery-gathering needs.
In response to Garthor
Good point... I always forget about the tag var when dealing with datums. (As opposed to atoms. Yeah, I know atoms are derived from datums, but there's no need to be picky about it. :-D)