Run time error 4: "Array index out of bounds"
#1

Hi , I need help with this problem please:

My server isn't starting because of this:

Quote:

[06:42:45] [debug] Run time error 4: "Array index out of bounds"
[06:42:45] [debug] Accessing element at index 5 past array upper bound 4
[06:42:45] [debug] AMX backtrace:
[06:42:45] [debug] #0 00043b0c in main () at C:\Users\x\Desktop\x\x\Linux\x\x.pwn:615
[06:42:45] Script[gamemodes/x.amx]: Run time error 4: "Array index out of bounds"
[06:42:45] Number of vehicle models: 0

Line 615 of my script :

Код:
	for(new i = 0; i<MAX_PLAYERS; i++) 
	{
		labelStats[i] = Create3DTextLabel(" ", -1, 0.0, 0.0, 4000.0, 50.0, 0, 1);
	}
Reply
#2

maybe this
Код:
for(new i = 0; i<=MAX_PLAYERS; i++)
{
	labelStats[i] = Create3DTextLabel(" ", -1, 0.0, 0.0, 4000.0, 50.0, 0, 1);
}
or you can try foreach for better
Код:
foreach (new i : Player)
{
   if(IsPlayerConnected(i))
   {
      labelStats[i] = Create3DTextLabel(" ", -1, 0.0, 0.0, 4000.0, 50.0, 0, 1);
   }
}
Reply
#3

As you're trying to loop through an array with the indexes of players. Then you should defined the array size of labelStats to MAX_PLAYERS.

Just as below

PHP код:
new labelStats[MAX_PLAYERS]; 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)