ID:178262
 
I want to know how to make lists, then give them a name, then access them later, and then I need to know how add stuff to them?

This is what I tried

mob
var
list
Languages = ""
Login()
Languages += "Common"
Languages += "Dwarven"
Languages += "Elven"
Languages += "Undercommon"
..()

Is this snippet right?

And later, do I try to access it like this?

if("Common" in usr.Languages)
usr << "cheese"

or whatnot? Is my code at al right, any help is much appreciated, I have tried to figure this out for weeks!
Ter13 wrote:
var
list
Languages = ""
Login()
Languages += "Common"
Languages += "Dwarven"
Languages += "Elven"
Languages += "Undercommon"
..()

Is this snippet right?

Nope. To initialize the list, use this:
Languages = list()

You should move that line to Login() or New(), though; I believe the way you've got it defined, all mobs would share the same list.
If you want them to share the same list, do this instead:
mob
var/list/Languages=list("Common","Dwarven","Elven","Undercommon")

You can also add a list from the list() proc to an existing list.

And later, do I try to access it like this?

if("Common" in usr.Languages)
usr << "cheese"

Yes, that will work. There are lots of ways to access a list.

Lummox JR
In response to Lummox JR
It's SO SIMPLE! Thank you lummox, it took me so long to figure this out! I... I Worship you in every way.

I just played Chord in an hour long game of incursion today, I whooped him big time though, half of the game was one battle, we had like a 400 tropp vs. as 150 troop battle, I totally slaughtered him, I had a ton of red t ape cards to use o nhim, he was pissed!
In response to Lummox JR
oh, one more thing, how do I add something to that list properly? Do I just do the Languages += "Blah"? or what?
In response to Ter13
Ter13 wrote:
oh, one more thing, how do I add something to that list properly? Do I just do the Languages += "Blah"? or what?

Yes, that will work just fine.

Once you get familiar with lists, I also recommend you check out my early BYONDscape article on associative lists (in the archives). Associative lists are one of the coolest features of BYOND, and definitely worth your time.

Lummox JR