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=476855)
Run time error 4: "Array index out of bounds" -
Loot - 20.11.2013
Hi there,
I'm getting an error whenever I spawn a detonator for some reason, probably due to it being in slot 12(?)
Do I need to omit the case weaponid 40 in this case?
Код:
[debug] Run time error 4: "Array index out of bounds"
[debug] Accessing element at index 12 past array upper bound 11
[debug] AMX backtrace:
[debug] #0 000706a8 in CheckWeapon (wid=12)
pawn Код:
stock GetWeaponSlot(weaponid)
{
new slot;
switch(weaponid)
{
case 0, 1: slot = 0;
case 2 .. 9: slot = 1;
case 10 .. 15: slot = 10;
case 16 .. 18, 39: slot = 8;
case 22 .. 24: slot = 2;
case 25 .. 27: slot = 3;
case 28, 29, 32: slot = 4;
case 30, 31: slot = 5;
case 33, 34: slot = 6;
case 35 .. 38: slot = 7;
case 40: slot = 12; // ->
case 41 .. 43: slot = 9;
case 44 .. 46: slot = 11;
}
return slot;
}
Check(playerid)
{
CheckWeapon(playerid, GetWeaponSlot(GetPlayerWeapon(playerid)));
}
CheckWeapon(playerid, wip)
{
// ...
}
// ...
Re: Run time error 4: "Array index out of bounds" -
Jefff - 20.11.2013
Show which array is used for this
you have
new Weapons[12] but should be Weapons[13]
Re: Run time error 4: "Array index out of bounds" -
yugecin - 20.11.2013
You don't show what's inside CheckWeapon, and there the error probably happens ig, so we can't really say (or the array)
Re: Run time error 4: "Array index out of bounds" -
Loot - 20.11.2013
Quote:
Originally Posted by Jefff
Show which array is used for this
you have
new Weapons[12] but should be Weapons[13]
|
Nice strike! That was definitely the issue, I've had an array of max 12 slots instead of 13. (so GetWeaponSlot returned 12 which is above the limit)
Quote:
Originally Posted by yugecin
You don't show what's inside CheckWeapon, and there the error probably happens ig, so we can't really say (or the array)
|
I never thought that the issue was above, thus I did not revealed anything else.
Cheers guys!