ID:273536
 
Is there a way to use list associations without always having to check for the list & making a new one (else get a bad index error)??
    PatchUp()
if(!Number) Number=new() //these lines here
if(!MissingNumber) MissingNumber=new()
if(Number[src]==(MissingNumber[src.Village]+1))
Number[src]--; MissingNumber[src.Village]++


Can you just define them with it? What are the ramifications of that if you can?
var/list
MissingNumber[]=new()
Number[]=new()
var/list
MissingNumber = list()
Number = list()

But make sure you never do MissingNumber = null to empty list, better MissingNumber = list()
In response to Ripiz (#1)
what about MissingNumber[src]=null??
In response to Saucepan Man (#2)
If MissingNumber[src] is number, text or reference it's fine, but if it's another list you'll have to do MissingNumber[src] = list()
In response to Ripiz (#3)
:O YOU CAN DO THAT?

SO like....
var/PeopleOnline=list()
Login()
PeopleOnline[src.Colour]+=src

mob/verb/Dance()
if(src in PeopleOnline["White"])
usr<<"You failed to perform any notable dance moves and no ladies thought you were cool. In fact all you achieved was knocking some big guys drink out of his hand... You had best run!"
else if(src in PeopleOnline["Black"])
usr<<"Your fantastic dance moves astound everyone! You score 1,000 ladies! Well done."
else if(src in PeopleOnline["Green"]
usr<<"Your alien dance moves are lost on these earthlings..."
In response to Saucepan Man (#4)
Doesn't mean src.Colour will be there >.>
If it's only 3 colors, you can define it in variable
var/list/PeopleOnline = list("White" = list(), "Black" = list(), "Green" = list())
In response to Ripiz (#5)
If it were a bajillion colours, would the initial method work (i'm sensing: no)
In response to Saucepan Man (#6)
Sadly no, you'll have to check if it's exists in list, if not then add and initialize list for it.
In response to Ripiz (#7)
src.Colour="slightly offish shade of red with a hint of magnolia"
if(!(src.Colour in PeopleOnline)) PeopleOnline+=list(src.Colour= list())
PeopleOnline[src.Colour]+=src


Like that?
In response to Saucepan Man (#8)
Colour = "slightly offish shade of red with a hint of magnolia"
if(!(Colour in PeopleOnline))
PeopleOnline += Colour
PeopleOnline[Colour] = list(src)
In response to Ripiz (#9)
Thankyou ^_^
enjoy this Old Spice Guy video as thanks :D
http://www.youtube.com/watch?v=SLz5ArupElA
In response to Ripiz (#9)
From my experience with lists(caching random crap), you don't need to add an item to associate it with something.
<dm>
if(!(Colour in PeopleOnline))
PeopleOnline[Colour] = list(src)