ID:161836
 
Adding/Taking to/from a list is easy...

var/list/LISTNAME=list()

LISTNAME+=insert
LISTNAME-=insert


However what If you want to add more? I can't precisely remember how to do it..

var/list/LISTNAME=List("1"="1","2"="2")


How would I be able to add
"3"="3" ?

3 things;

1) This is all hypothetical variables, this isn't actual reference to code. A list to determine a number is just daft.

2) Is it possible to allow more than one thing defined to each? Such as..
Var/list/LISTNAME=List("1"="1"&"1.5","2"="2"&"2.5")


3) I apologies that this probably seems easy and I'm overlooking this however my mind does not seem to be working today.
To both questions, yep.

To add associative values, such as "1"="1":

list["Category"] = "SomeValue"


To contain multiple items in one slot, you can use multi-dimensional lists like this:

var/list[] = list("Item1",list("Item2.1","Item2.2"))
In response to DivineO'peanut
DivineO'peanut wrote:
To both questions, yep.

To add associative values, such as "1"="1":

> list["Category"] = "SomeValue"
>

To contain multiple items in one slot, you can use multi-dimensional lists like this:

> var/list[] = list("Item1",list("Item2.1","Item2.2"))
>


So say for example I want to add..

Bunnie
Chicken
Grass

all in one go to the list.. how would I go about it? I'm sorry but I'm just not quite understanding this here.

And then how would I examine the list for it all? >.>
In response to Bunnie
var/somelist[] = list(list("Bunnie","Chicken","Grass))


To access these values:

somelist[index][other_index]


So, if you want to see what is in the 2nd slot of the first item in the list ("Chicken" in this case), you can do this:

</dm>
somelist[1][2]
</dm>
In response to DivineO'peanut
DivineO'peanut wrote:
> var/somelist[] = list(list("Bunnie","Chicken","Grass))
>

To access these values:

> somelist[index][other_index]

So, if you want to see what is in the 2nd slot of the first item in the list ("Chicken" in this case), you can do this:

</dm>
somelist[1][2]
</dm>

Ahh that is similar to other coding, but you didn't quite answer my question, how would I ADD Them?

I.e

somelist+=list("Bunnie","Chicken","Grass")


Or have I just guessed that right? >_>
In response to Bunnie
You've guessed right. :-)

But, I'm pretty sure I have answered it! You never asked how to add the lists. :-/
In response to DivineO'peanut
DivineO'peanut wrote:
You've guessed right. :-)

var/somelist[] = list()
somelist+=list("Bunnie","Chicken","Grass")

if(somelist.Find("Bunnie"))
world<<"We found Bunnie!"


Now how do I get all the bits 'associated' with Bunnie? I.E

world<<"We found Bunnie! [somelist.Bunnie.1] [somelist.Bunnie.2]"


.1 being Chicken
.2 Being Grass
In response to Bunnie
var/Bunnie/B = somelist[1][2]
usr << "[B.type] was found in somelist[1][2]."
In response to DivineO'peanut
DivineO'peanut wrote:
> var/Bunnie/B = somelist[1][2]
> usr << "[B.type] was found in somelist[1][2]."
>


I'm trying to refrain from hard-coding this, which is why I keep making references to being able to add/remove things from the list and still find what I'm looking for.

How can I add/take it to/from..
var/list/Somelist = list()
In response to Bunnie
for(var/list in somelist)
for(var/item in list)
if(istype(item,/Bunnie))
// Do something.


Oh, you may want to check if <code>list</code> is actually a list.

if(istype(list,/list))
// Do stuff.
In response to DivineO'peanut
DivineO'peanut wrote:
> for(var/list in somelist)
> for(var/item in list)
> if(istype(item,/Bunnie))
> // Do something.
>


var/list/somelist = list()

somelist+=list("Bunnie","Chicken","Grass")

//somelist=list(list("Bunnie","Chicken","Grass"))

for(var/list in somelist)
for(var/getlist in list)
if(istype(getlist,"Bunnie"))
world<<"Found Bunnie!"
world<<"Found [getlist] with [getlist.1] [getlist.2]


Right?
Bunnie wrote:
However what If you want to add more? I can't precisely remember how to do it..

var/list/LISTNAME=List("1"="1","2"="2")

How would I be able to add
"3"="3" ?

LISTNAME["3"] = "3"

2) Is it possible to allow more than one thing defined to each? Such as..
Var/list/LISTNAME=List("1"="1"&"1.5","2"="2"&"2.5")


You make the association into a list itself. So:

var/list/LISTNAME = list("1" = list("1", "1.5"), "2" = list("2", "2.5"))
LISTNAME["3"] = list("3","3.5")

LISTNAME["3"] will now give you list("3", "3.5").