Help me with this
#1

Код HTML:
[13:08:10] [debug] Accessing element at index 30 past array upper bound 29 
[13:08:10] [debug] AMX backtrace: 
[13:08:10] [debug] #0 0006c1e4 in public TimeConn () from GM.amx 
[13:09:17] [debug] Run time error 4: "Array index out of bounds" 
[13:09:17] [debug] Accessing element at index 30 past array upper bound 29 
[13:09:17] [debug] AMX backtrace: 
[13:09:17] [debug] #0 0006c1e4 in public TimeConn () from GM.amx
Timeconn

Код:
public TimeConn()
{
	for(new i=0;i<=MAX_PLAYERS;i++)
	{
		if(PLAYERLIST_authed[i] && IsPlayerConnected(i) && PlayerInfo[i][jail] == 0 && iAFKp[i] < 4)
		{
			PlayerInfo[i][playertime] = PlayerInfo[i][playertime];
			PlayerInfo[i][playertime] +=200;
   			new query[250], pname[25];
 			GetPlayerName(i, pname, 24);
 			format(query, sizeof(query), "UPDATE PlayerInfo SET playertime=%d WHERE user='%s'", PlayerInfo[i][playertime], pname);
			mysql_query(query);
		}
	}
	return 1;
}
Reply
#2

Код:
for(new i=0;i<MAX_PLAYERS;i++)
Reply
#3

whats the diff between mine and yours lol ...... still need help
Reply
#4

Quote:
Originally Posted by TheLegend1
Посмотреть сообщение
Код HTML:
[13:08:10] [debug] Accessing element at index 30 past array upper bound 29 
[13:08:10] [debug] AMX backtrace: 
[13:08:10] [debug] #0 0006c1e4 in public TimeConn () from GM.amx 
[13:09:17] [debug] Run time error 4: "Array index out of bounds" 
[13:09:17] [debug] Accessing element at index 30 past array upper bound 29 
[13:09:17] [debug] AMX backtrace: 
[13:09:17] [debug] #0 0006c1e4 in public TimeConn () from GM.amx
Timeconn

Код:
public TimeConn()
{
	for(new i=0;i<=MAX_PLAYERS;i++)
	{
		if(PLAYERLIST_authed[i] && IsPlayerConnected(i) && PlayerInfo[i][jail] == 0 && iAFKp[i] < 4)
		{
			PlayerInfo[i][playertime] = PlayerInfo[i][playertime];
			PlayerInfo[i][playertime] +=200;
   			new query[250], pname[25];
 			GetPlayerName(i, pname, 24);
 			format(query, sizeof(query), "UPDATE PlayerInfo SET playertime=%d WHERE user='%s'", PlayerInfo[i][playertime], pname);
			mysql_query(query);
		}
	}
	return 1;
}
I really want to know why you're updating the player's playertime in the database everytime. And It's for all players!
Reply
#5

I'd have thought a Out of Bounds issue would come up at compile time somehow...
Reply
#6

Quote:
Originally Posted by TheLegend1
Посмотреть сообщение
whats the diff between mine and yours lol ...... still need help
Difference is that yours is going out of bounds because your using 'less than or equal to' MAX_PLAYERS.

When using MAX_PLAYERS to loop make sure it's like this:

Код:
for(new i=0; i < MAX_PLAYERS; ++i)
Or
Код:
for(new i=0; i != MAX_PLAYERS; ++i)
Not

Код:
for(new i=0; i <= MAX_PLAYERS; ++i)
Numbers start from zero, so a valid index to an array that is size of MAX_PLAYERS is 0 ... MAX_PLAYERS -1.

https://sampwiki.blast.hk/wiki/Control_Structures#OBOE
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)