Accessing element at index 50 past array upper bound 49
#1

Код:
new Gun[50][MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
SetTimerEx("GunTimer", 500, true, "i", playerid);
return 1;
}

public GunTimer(playerid)
{
for(new i=0;i<50;i++) 
{ 
if(Gun[i][playerid]  == 42)
{
 Gun[i][playerid]  = 0; 
}
}
	return 1;
}
When I join server it starts printing :

Код:
[15:24:13] [debug]  Accessing element at index 50 past array upper bound 49
[15:24:13] [debug] AMX backtrace:
[15:24:13] [debug] #0 000352f4 in ?? (0) from GunTest.amx
[15:24:13] [debug] #1 000a2198 in public GunTimer (0) from GunTest.amx
Reply
#2

Quote:

[15:24:13] [debug] Accessing element at index 50 past array upper bound 49

Means:
Your script trying to access the array on index: 50; While the array can't handle more than 49.
PHP код:
new Gun[51][MAX_PLAYERS]; 
Simple as that.
Reply
#3

But the question is - how the script is trying access the 50th element?
Reply
#4

Quote:
Originally Posted by PawnHunter
Посмотреть сообщение
PHP код:
new Gun[51][MAX_PLAYERS]; 
Simple as that.
What?

As far as I can see there is nothing wrong with the snippet that was posted, although it is still always better to use the sizeof operator wherever possible. From the backtrace it seems like public GunTimer calls another function which is not included in the snippet.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)