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

Please help wit this error

pawn Код:
[06:17:30] [debug] Run time error 4: "Array index out of bounds"
[06:17:30] [debug]  Attempted to read/write array element at index 255 in array of size 255
[06:17:30] [debug] AMX backtrace:
[06:17:30] [debug] #0 00082b7c in public OnVehicleSpawn (vehicleid=255) at #:\Hidden\Hidden\gamemodes\Hidden.pwn:11707
[06:17:30] [debug] #1 native SetVehicleToRespawn () from samp03svr
[06:17:30] [debug] #2 000c1e6c in LoadVehicle (i=255) at #:\Hidden\Hidden\gamemodes\Hidden.pwn:16345
[06:17:30] [debug] #3 000c0630 in LoadVehicles () at #:\Hidden\Hidden\gamemodes\Hidden.pwn:16292
[06:17:30] [debug] #4 00089544 in public zcmd_OnGameModeInit () at #:\Hidden\Hidden\gamemodes\Hidden.pwn:12246
[06:17:30] [debug] #5 native CallLocalFunction () from samp03svr
[06:17:30] [debug] #6 00009e0c in public IRC_OnGameModeInit () at #:\Hidden\Hidden\pawno\include\zcmd.inc:51
[06:17:30] [debug] #7 native CallLocalFunction () from samp03svr
[06:17:30] [debug] #8 000098b8 in public OnGameModeInit () at #:\Hidden\Hidden\pawno\include\irc.inc:200
[06:17:30] [debug] Run time error 4: "Array index out of bounds"
[06:17:30] [debug]  Attempted to read/write array element at index 256 in array of size 255
pawn Код:
public OnVehicleSpawn(vehicleid)
{
    if(vehicleid>sizeof(Vehicles)) return DestroyVehicle(vehicleid);
    vTrailer[vehicleid] = 0;
    CarBombActive[vehicleid] = 0;
    vehicleGuns[vehicleid] = 0;
    vehicleBullets[vehicleid] = 0;
    for(new i=0;i<13;i++)
  {
    VehicleWeapon[vehicleid][i]   = 0;
    VehicleAmmo[vehicleid][i]     = 0;
  }
  HasGunCrates[vehicleid] = 0;
    HasBulletCrates[vehicleid] = 0;
  comps[vehicleid][guns] = 0;
  comps[vehicleid][oil] = 0;
  comps[vehicleid][alchool] = 0;
  comps[vehicleid][money] = 0;
  comps[vehicleid][drugs] = 0;
  comps[vehicleid][stuffs] = 0;
  compscar[vehicleid] = 0; //line 11707
}
Reply
#2

How have you defined the variable "Vehicles"?

Do you have any other code in your script using the variable Vehicles? Or just anything around vehicles generally?
Reply
#3

I have variables for vehicles and yes.
Reply
#4

Show lines 11707, 16345, 16292 and 12246.
Reply
#5

I guess this happens when the loop reach to a number and that number is not in the array
Reply
#6

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
Show lines 11707, 16345, 16292 and 12246.
pawn Код:
11707 = compscar[vehicleid] = 0;
16345 = SetVehicleToRespawn(i);
16292 = LoadVehicle(i);
12246 = SendRconCommand("mapname Los Santos");
Reply
#7

BUMP! Anyone?
Reply
#8

Replace
PHP код:
if(vehicleid>sizeof(Vehicles)) 
with
PHP код:
if(vehicleid >= sizeof(Vehicles)) 
If you have an array size 255 then sizeof will return 255 BUT the highest index you can access is 254.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)