ID:172174
 
While trying to become better at DM, I need to know about lists. THe DM reference doesnt help... How do i do lists? can I have a small snippet?
While trying to become better at DM, I need to know about lists. THe DM reference doesnt help... How do i do lists? can I have a small snippet?

A list is just an ordered(or associated with a key) collection of data.

var/list/L     //Defines a list reference but similiar
//to when you do this with a mob no list
//actually exsists yet

L = new() //Creates an empty list which L points to

L.Add("String 1") //Adds an item to the list
L.Add("String 2") //And another
L.Add("String 3") //And another

for(var/T in L) // Cycle through each item in the list
world << T // Output the list item

for(var/i = 3; i > 0; --i) //Set up a loop to access via index
world << L[i] // Outputs the ith element in the list
In response to Theodis
just to kinda get a better idea i pasted it into a dm file then ran it and it ave me these erros

bad argument definition 3 times at the string 2 string 3 and for(var thingy
In response to Konamix
That code won't run. It's just a bunch of examples of the type of things you can do with lists.

I suggest you check out Chapter 10 of the DM Guide. (The link to the full guide is on the left.)
In response to Crispy
OK, let me get my question out. If I made a list like this

mob
proc
Log2()
var/list/classes
classes = new()
classes.Add("Warrior")
classes.Add("Paladin")
is what I have is that.. I want it to bring up a selection list where it shows what i have in the list like
---------------
-Warrior -
-Paladin -
-Cancel -
---------------
then would i usr if("Warrior") to see if thats what they picked?
In response to Konamix
This should work. "in classes" represents all the things in the classes list and you add "Cancel" to the choices also with +list("Cancel") .
var/M = input("What class would you like to choose?","Class") in classes + list("Cancel")
if(M == "Paladin")
src << "Hey you chose Paladin"
if(M == "Warrior")
src << "Hey you chose Warrior"
if(M == "Cancel")
src << "Hey you didnt choose nothing"
In response to Konamix
thanks a lotz turles
In response to Turles9000
Rather than adding a "Cancel" option, I prefer to do the last bit of the input() like this:

in classes as null|anything

That way, a cancel *button* will appear on the dialog. Much nicer. =)
In response to Crispy
That code won't run. It's just a bunch of examples of the type of things you can do with lists.

The only thing it lacks is a place to be run :P. I know it runs since I threw it in a verb and all was well.
In response to Turles9000
Use else if()s there. Always use else if()s when choosing between different options. It's faster and less prone to error.