ID:942248
 
(See the best response by Albro1.)
mob/verb/list_add(mob/m)
if(m.ingroup==0)
friend1.Add(m)
m.ingroup=1
while(1)
var/mob/x=friend1[1]
var/mob/y=friend1[2]
if(src.loc==locate(12,6,1) && (x in friend1) && (y in friend1))
x.loc=locate(12,3,1)
y.loc=locate(11,9,1)
cancelfor=1//cancel below if statement
else if(cancelfor==0 && x in friend1 && src.loc==locate(12,6,1))
x.loc=locate(12,3,1)
sleep(10)



I'm making a party system that encounters enemies and whenever I add a friend it says list index out of bounds. I think it says that because var/mob=friend1[2] doesn't exist and I'm trying to define it as a variable. How do I make it define only if there is a second person in the list?
Best response
You have to see if friend1[2] exists - you can do this by comparing it to list.len.
how do i do that?
TheDarkChakra wrote:
>     if(m.ingroup==0)// BAD!
> else if(cancelfor==0 && x in friend1 && src.loc==locate(12,6,1)) // BAD!!!!
>

BAD programming BAD! ! = false if(!thismeansfalse){dostuff()}
In response to A.T.H.K (#3)
A.T.H.K wrote:
TheDarkChakra wrote:
> >     if(m.ingroup==0)// BAD!
> > else if(cancelfor==0 && x in friend1 && src.loc==locate(12,6,1)) // BAD!!!!
> >

BAD programming BAD! ! = false if(!thismeansfalse){dostuff()}


I'm a newb. Tell me what is GOOD programming. I'd like to learn.
Using len worked