[Pawn] Help with a loop - Printable Version + open.mp forum (https://forum.open.mp) -- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3) --- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10) --- Thread: [Pawn] Help with a loop (/showthread.php?tid=3025) |
Help with a loop - Neckiy - 2025-01-05 So I feel very stupid right now but can somebody help me with this problem. I'm making a loop which loads the mysql database data for my admin system. Code: #define MAX_ADMINS 25 The error I get is: [debug] Run time error 4: "Array index out of bounds" [2025-01-05T16:46:11+0100] [Info] [debug] Attempted to read/write array element at index 25 in array of size 25 [2025-01-05T16:46:11+0100] [Info] [debug] AMX backtrace: [2025-01-05T16:46:11+0100] [Info] [debug] #0 000243c8 in public OnAdminLoad (i=24) at C:\Users\neman\Desktop\openmp server\gamemodes\skripta.pwn:120 Even though the loop loops from 0 to 24 and then I load it "i+1" because in my database, the Admin Slots are from 1 to 25? Can somebody explain where the problem is? RE: Help with a loop - samuelmatheus0502 - 2025-01-06 I couldn't understand very well. Why are you loading 25 admins at once? without them being connected RE: Help with a loop - Neckiy - 2025-01-06 (2025-01-06, 12:11 AM)samuelmatheus0502 Wrote: I couldn't understand very well. Why are you loading 25 admins at once? It just loads every admin data and puts those values into variables when the server starts. RE: Help with a loop - samuelmatheus0502 - 2025-01-07 I believe the problem is with MAX_ADMINS, as the maximum is 25, but you started the loop with 0 and from 0 to 25 gives 26 spaces. change this: "for(new i = 0; i < MAX_ADMINS; i++)" that's why: for(new i = 1; i < MAX_ADMINS; i++) and also remove the "+1" from variable i in the OnAdminLoad callback |