Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: riseryn on Fri 14/12/2007 03:25:18

Title: array index out of bounds [SOLVED]
Post by: riseryn on Fri 14/12/2007 03:25:18
Hi
after wandering through the forum for one hour without finding a solution i'm completely lost.

the array ball is part of a structure and there is no problem with it.
it goes from ball[0] to ball[4]

int randi = Random(4);
int randj = Random(2)+1;
int k=0;
while(k<5)
{
if(k == randi){ ball[k].weight = randj;}

else{ball[k].weight =1;   }
k++;
}

when running, this code give me:
Error:  Array index out of bounds (index:4 bounds:0..3)

I dont understand why :(
maybe its very simple :)

Any suggestions?

Thanks
Title: Re: array index out of bounds
Post by: Gilbert on Fri 14/12/2007 03:30:24
If you defind the array as something like:
int ball[4];
its index actually runs from 0 to 3.

If you want the index to run from 0 to 4, you need:
int ball[5];
Title: Re: array index out of bounds
Post by: riseryn on Fri 14/12/2007 03:45:44
thanks for your quick response

it works