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

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)
{
    // ... 
}
// ...
Reply
#2

Show which array is used for this
you have
new Weapons[12] but should be Weapons[13]
Reply
#3

You don't show what's inside CheckWeapon, and there the error probably happens ig, so we can't really say (or the array)
Reply
#4

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)