04.10.2013, 13:35
I am using foreach in advancespectate code, and on occations it gives OOB error.
Here is the code and i cant seem to figure out why, when i tested alot without getting error. But after some uptime, there it is, run time error.
Im using y_iterate 20, MAX_PLAYERS = 110 and here is code;
pawn Код:
[10:30:19] [debug] Run time error 4: "Array index out of bounds"
[10:30:19] [debug] Accessing element at index 111 past array upper bound 110
[10:30:19] [debug] AMX backtrace:
[10:30:19] [debug] #0 00223164 in public AdvanceSpectate (playerid=15) at C:\Users\me\Desktop\Dev\gamemodes\sa-tdm_7.004.pwn:22989
Im using y_iterate 20, MAX_PLAYERS = 110 and here is code;
pawn Код:
if(Iter_Last(Character) == playerid) last = Iter_Prev(Character, playerid); // if playerid is the last id, the prev id will be set as last
else last = Iter_Last(Character); // if not playerid is last, use the actual last id
if(gSpectateID[playerid] == last) gSpectateID[playerid] = Iter_First(Character); // if player was spectating last player, set to first.
for(new i = gSpectateID[playerid]; (i = Iter_Next(Character, i)) != Iter_End(Character); ) // OOB :(