SA-MP Forums Archive
Need help with a loop - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need help with a loop (/showthread.php?tid=297528)



Need help with a loop - saker277 - 16.11.2011

I am trying to make a loop that will make and array hold a list of all of the different vehicle ids but for some reason it only stores the ids 400-610 and the loop never ends, i have tried to fix it but i can't see what i am doing wrong. could someone please tell me what the problem is?
here is the code for the loop:
Код:
        new vehids[211];
	new idx=0;
	for(new x=400;x<612;x++)
	{
	    vehids[idx]=x;
	    printf("x val is now %d",x);
	    idx++;
	}
	printf("Loop is done");



Re: Need help with a loop - Sinner - 16.11.2011

Your array goes out of bounds, you declare an array of 200 bytes but you set the x to be "vehid[400+]".


Re: Need help with a loop - saker277 - 16.11.2011

oops. I am so used to my eclipse ide for java which tells me when my array isn't big enough. thanks for the help man.


Re: Need help with a loop - Sinner - 16.11.2011

Quote:
Originally Posted by saker277
Посмотреть сообщение
oops. I am so used to my eclipse ide for java which tells me when my array isn't big enough. thanks for the help man.
Sorry I was wrong, your array needs to be atleast 612 large, your IDs will then start from array[400] to array[611]. My bad.


Re: Need help with a loop - sabretur - 16.11.2011

Should this work:
pawn Код:
new vehids[212];
for(new x = 0;x < 212;x++)
{
    vehids[x] = 400 + x;
    printf("x val is now %d",400 + x);
}
print("Loop is done");