[REP++ WHO HELPS] Run time error 4: "Array index out of bounds"
#1

Hello , i can't get this work , i have 25 turfs in my mysql database, i want to show an error when a player is not near them , i make this with IsPlayerInRange , don't ask why.


I get SERVER:Unknown command if i am not in a turf , and if i am it's goes SUCCESS!

Error:
pawn Код:
[11:27:42] [debug] Run time error 4: "Array index out of bounds"
[11:27:42] [debug]  Accessing element at index 26 past array upper bound 25
I tried to put 25 instead of 26 but gamemode goes to Unknown.
pawn Код:
new TurfInfo[26][ttInfo];

new TurfInfo[26];



CMD:attack(playerid, params[])
{
    new turfid;
    for(new xf = 0; xf <= sizeof(TurfInfo); xf++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 4.0, TurfInfo[xf][ttPosX], TurfInfo[xf][ttPosY], TurfInfo[xf][ttPosZ]))
        {
                    turfid = xf;
            break;
        }
    }
    if(turfid == 0) return SendClientMessage(playerid, COLOR_WHITE, "ERROR!");
    if(turfid > 0) return SendClientMessage(playerid, COLOR_WHITE, "SUCCES!");
    return 1;
}
Reply
#2

try this? o.o
PHP код:
new TurfInfo[26][ttInfo];

new 
TurfInfo[26];



CMD:attack(playeridparams[])
{
    new 
turfid;
    for(new 
xf 0xf <= sizeof(TurfInfo); xf++)
    {
         if(
IsPlayerInRangeOfPoint(playerid4.0TurfInfo[xf][ttPosX], TurfInfo[xf][ttPosY], TurfInfo[xf][ttPosZ]))
           {
                    
turfid xf;
            break;
        }
    }
    if(
turfid == 0) return SendClientMessage(playerid, -1"ERROR!");
    }
    else if(
turfid 0) return SendClientMessage(playerid, -1"SUCCES!");
    }
    else { 
SendClientMessage(playerid, -1"YOUR MESSAGE IF NOT IN A TURF");
    }
    return 
1;

Reply
#3

Instead of using "<=" try just "<".
Reply
#4

PHP код:
for(new xf 0xf <= sizeof(TurfInfo); xf++) 
to
PHP код:
for(new xf 0xf sizeof(TurfInfo); xf++) 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)