foreach help, out of bounds error.
#1

I am using foreach in advancespectate code, and on occations it gives OOB error.
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
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 Код:
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 :(
Reply
#2

Can you show us the line 22989 please?
Could be something regarding MAX_PLAYERS I think.
Reply
#3

Line 22989 is there, commented with OOB
Reply
#4

Bump
Reply
#5

You actually set i 2 times on the loop, the first one with gSpectateID[playerid]; and then with Iter_Next(Character, i). You also don't increase i number at the end of the loop..
Reply
#6

Quote:
Originally Posted by ]Rafaellos[
Посмотреть сообщение
You actually set i 2 times on the loop, the first one with gSpectateID[playerid]; and then with Iter_Next(Character, i). You also don't increase i number at the end of the loop..
The thing is working, its based of the internal foreach macro:
pawn Код:
for (new i = Iter_Begin(Some); (i = Iter_Next(Some, i)) != Iter_End(Some); )
Instead of using Iter_Begin, my loop starts at the ID player was spectating.
The problem is that sometimes it gives out of bound error.
But thanks for trying..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)