Run time error 4: "Array index out of bounds" - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Run time error 4: "Array index out of bounds" (
/showthread.php?tid=633705)
Run time error 4: "Array index out of bounds" -
Blackaslan - 06.05.2017
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);
}
Re: Run time error 4: "Array index out of bounds" -
Kucin666 - 06.05.2017
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);
}
}
Re: Run time error 4: "Array index out of bounds" -
ShihabSoft - 06.05.2017
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];