SA-MP Forums Archive
For 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: For Loop (/showthread.php?tid=616423)



For Loop - Penguin1997 - 04.09.2016

Код:
#undef MAX_PLAYERS
#def MAX_PLAYERS 100

new Job1[MAX_PLAYERS][19];

public OnPlayerConnect(playerid)
{
for(new i = 0; i < sizeof(Job1); i++)
{
Job1[playerid][i] = 0; // Line 5094
}
return 1;
}
Now if i do this I get
Код:
[22:40:08] [debug] Run time error 4: "Array index out of bounds"
[22:40:08] [debug]  Accessing element at index 12 past array upper bound 11
[22:40:08] [debug] AMX backtrace:
[22:40:08] [debug] #0 000776f0 in ?? (... <1 argument>) at G:\ZS\gamemodes\gamemodes\gamemodes\bttdmzmapocalypse.pwn:5094
[22:40:08] [debug] #1 0000f11c in public Itter_OnPlayerConnect (playerid=1) at G:\ZS\pawno\include\YSI\y_hooks/impl.inc:618
[22:40:08] [debug] #2 0000888c in public SSCANF_OnPlayerConnect (playerid=1) at G:\ZS\pawno\include\YSI\y_iterate.inc:646
[22:40:08] [debug] #3 00001118 in public OnPlayerConnect (playerid=1) at G:\ZS\pawno\include\sscanf2.inc:236



Re: For Loop - Konstantinos - 04.09.2016

You want to loop through the indexes of the second dimension so the correct way is:
Код:
for(new i = 0; i < sizeof Job1[]; i++)



Re: For Loop - Penguin1997 - 04.09.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
You want to loop through the indexes of the second dimension so the correct way is:
Код:
for(new i = 0; i < sizeof Job1[]; i++)
Thanks!