[debug] Run time error 4: "Array index out of bounds" problem - 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: [debug] Run time error 4: "Array index out of bounds" problem (
/showthread.php?tid=669045)
[debug] Run time error 4: "Array index out of bounds" problem -
MaestrulFritz - 30.08.2019
Hello everyone! I have this problem as I am very new to scripting
Code:
[debug] AMX backtrace:
[22:09:55] [debug] #0 004ae518 in public cmd_exitgarage (0, 10500072) from GM.amx
[22:09:55] [debug] #1 native CallLocalFunction () from samp-server.exe
[22:09:55] [debug] #2 0000089c in public OnPlayerCommandText (0, 10500024) from GM.amx
[22:09:57] [debug] Run time error 4: "Array index out of bounds"
[22:09:57] [debug] Attempted to read/write array element at negative index -1
This is the command:
Code:
CMD:exitgarage(playerid, params[])
{
if(pInfo[playerid][aVar][61] != -1 && IsPlayerInRangeOfPoint(playerid, 3.0, 1341.2281,-1548.8905,10037.3174))
if(GetPlayerState(playerid) == 2)
{
SetVehicleVirtualWorld(pInfo[playerid][aVar][1], 0), SetVehiclePos(pInfo[playerid][aVar][1], Houses[pInfo[playerid][aVar][61]][GEnterX], Houses[pInfo[playerid][aVar][61]][GEnterY], Houses[pInfo[playerid][aVar][61]][GEnterZ]), SetPlayerPos(playerid, Houses[pInfo[playerid][aVar][61]][GEnterX], Houses[pInfo[playerid][aVar][61]][GEnterY], Houses[pInfo[playerid][aVar][61]][GEnterZ]),
SetPlayerVirtualWorldEx(playerid, Iter_Contains(Warp, playerid) || Iter_Contains(Warp2, playerid) ? (pInfo[playerid][aVar][87]) : (0)), PutPlayerInVehicle(playerid, pInfo[playerid][aVar][1], 0);
pInfo[playerid][aVar][61] = -1;
}
if(GetPlayerState(playerid) == 1)
{
SetPlayerPos(playerid, Houses[pInfo[playerid][aVar][61]][GEnterX], Houses[pInfo[playerid][aVar][61]][GEnterY], Houses[pInfo[playerid][aVar][61]][GEnterZ]),
SetPlayerVirtualWorldEx(playerid, Iter_Contains(Warp, playerid) || Iter_Contains(Warp2, playerid) ? (pInfo[playerid][aVar][87]) : (0)),
pInfo[playerid][aVar][61] = -1;
}
return 1;
}
I also got this :
Code:
[22:53:15] [debug] Run time error 4: "Array index out of bounds"
[22:53:15] [debug] Attempted to read/write array element at negative index -1
[22:53:15] [debug] AMX backtrace:
[22:53:15] [debug] #0 003568c0 in public OnPlayerLogin (1) from GM.amx
Re: [debug] Run time error 4: "Array index out of bounds" problem -
Nero_3D - 31.08.2019
your third if statment isn't under your first if statment, so aVar[61] can be -1 in your third if statement, either use brackets or only put one statment under a bracketless if statement
pawn Code:
// your structure
if(/*code*/) // if#1
if(/*code*/) // if#2, only valid after if#1
if(/*code*/) // if#3, works without if#1
// either use this
if(/*code*/) // if#1
if(/*code*/) // if#2
else if(/*code*/) // if#3
// or this
if(/*code*/) // if#1
{
if(/*code*/) // if#2
if(/*code*/) // if#3
}
// or this
if(/*code*/) // if#1
switch(/*code*/)
{
case /*constant*/: // if#2
case /*constant*/: // if#3
}
// or this
if(/*code*/) // if#1
{
switch(/*code*/)
{
case /*constant*/: // if#2
case /*constant*/: // if#3
}
}
Also what is with these numbers from aVar, why not use an second enum?