• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Help with a loop
#1
Star 
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

public OnGameModeInit() {
handle = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);

new query[128];
for(new i = 0; i < MAX_ADMINS; i++) {
mysql_format(handle, query, sizeof(query), "SELECT * FROM admini WHERE Slot='%d'", i);
mysql_tquery(handle, query, "OnAdminLoad", "i", i);
}

return 1;
}

forward OnAdminLoad(i);
public OnAdminLoad(i) {
if(cache_num_rows() > 0) {
cache_get_value(0, "Ime", AdminInfo[i+1][aIme], 25);     // THIS IS WHERE THE ERROR OCCURS
cache_get_value_int(0, "MinNeaktivnost", AdminInfo[i+1][aMinNeaktivnost]);
cache_get_value_int(0, "Neaktivnost", AdminInfo[i+1][aNeaktivnost]);
cache_get_value_int(0, "Zauzeto", AdminInfo[i+1][aZauzeto]);
cache_get_value_int(0, "Level", AdminInfo[i+1][aLevel]);
cache_get_value(0, "ImeLevel", AdminInfo[i+1][aImeLevel], 32);
} else {
print("Ucitavanje Admin Databaze nije uspelo.");
}
return true;
}

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?
  Reply


Messages In This Thread
Help with a loop - by Neckiy - 2025-01-05, 03:47 PM
RE: Help with a loop - by samuelmatheus0502 - 2025-01-06, 12:11 AM
RE: Help with a loop - by Neckiy - 2025-01-06, 02:27 PM
RE: Help with a loop - by samuelmatheus0502 - 2025-01-07, 07:20 PM

Forum Jump: