SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 11/11/2019, 09:38 PM   #11
Th3N0oB
Big Clucker
 
Join Date: Oct 2016
Location: Ecuador
Posts: 132
Reputation: 1
Default Re: [HELP] Run time error 4: "Array index out of bounds"

I saved these variables within the gamemode. Is this why the error occurs, and if so, with what other name would I replace 'actorid'?

pawn Code:
new actorid[20];
    actorid[1] = CreateActor(280, 246.404174,120.395568,1003.266967,178.847152);
    actorid[2] = CreateActor(307, 238.564437,112.894973,1003.218750,268.148071);
    actorid[3] = CreateActor(300, 253.797485,117.371421,1003.218750,93.306335);
    actorid[4] = CreateActor(71, 219.338485,116.030166,999.015625,180.895050);
    actorid[5] = CreateActor(281, 1580.795654,-1634.127685,13.562070,3.378870);

    actorid[6] = CreateActor(64, 1208.2064,-6.2447,1001.3281,180.9896);
    actorid[7] = CreateActor(85, 1221.3612,8.5217,1001.3356,131.3608);
    actorid[8] = CreateActor(152, 1215.6638,-6.3362,1001.3281,95.1821);
    actorid[9] = CreateActor(178, 1219.7606,-6.4455,1001.3281,178.2887);

    actorid[10] = CreateActor(155, 373.7149,-117.2781,1001.4995,177.6028);
    actorid[11] = CreateActor(155, -1260.9850,2121.6504,1246.5457,181.7688);
    actorid[12] = CreateActor(25, -1253.4526,2118.3821,1246.5457,175.7945);
    actorid[13] = CreateActor(163, -1245.2422,2116.1465,1246.5457,29.4371);
    actorid[14] = CreateActor(223, -1248.9423,2095.2004,1246.6360,72.3647);

    SetActorVirtualWorld(actorid[1], 1);
    SetActorVirtualWorld(actorid[2], 1);
    SetActorVirtualWorld(actorid[3], 1);
    SetActorVirtualWorld(actorid[4], 1);
    SetActorVirtualWorld(actorid[5], 0);
    SetActorVirtualWorld(actorid[10], 9);
    SetActorVirtualWorld(actorid[11], 1);
    SetActorVirtualWorld(actorid[12], 1);
    SetActorVirtualWorld(actorid[13], 1);

    SetActorVirtualWorld(actorid[6], 12);
    ApplyActorAnimation(actorid[6], "STRIP","STR_Loop_A", 4.1,1,0,0,1,0);
    SetActorVirtualWorld(actorid[7], 12);
    ApplyActorAnimation(actorid[7], "STRIP","STR_Loop_A", 4.1,1,0,0,1,0);
    SetActorVirtualWorld(actorid[8], 12);
    ApplyActorAnimation(actorid[8], "STRIP","STR_Loop_A", 4.1,1,0,0,1,0);
    SetActorVirtualWorld(actorid[9], 12);
    ApplyActorAnimation(actorid[9], "STRIP","STR_Loop_A", 4.1,1,0,0,1,0);
    SetActorVirtualWorld(actorid[14], 1);
    ApplyActorAnimation(actorid[14], "ped", "SEAT_down", 4.1,0,0,0,1,0);
Th3N0oB is offline   Reply With Quote
Old 12/11/2019, 05:46 AM   #12
Jstylezzz
High-roller
 
Jstylezzz's Avatar
 
Join Date: Sep 2011
Location: Netherlands
Posts: 1,859
Reputation: 1571
Default Re: [HELP] Run time error 4: "Array index out of bounds"

What the warning is trying to tell you, is that somewhere in the script there is another variable with the same name (be it within a function or global). The easiest fix would be to change the name of the variables you posted above. You can rename them with anything you see fit; Best is to choose something that will help you remember what these variables refer to exactly. If they were actors for a specific mission for example, you could call them mission01ActorId.

Also, keep in mind that arrays count from 0 That means you can start with element zero. The biggest index you can use is array size - 1 (since we count from 0), so in the case of the actor variable the highest index would be 19.
Code:
new actor[20];
actor[0] = .....
actor[1] = .....
...
actor[19] = ...
Jstylezzz is offline   Reply With Quote
Old 12/11/2019, 07:13 AM   #13
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 755
Reputation: 147
Default Re: [HELP] Run time error 4: "Array index out of bounds"

pawn Code:
...\pawno\include\YSI_Data\y_foreach\y_foreach_iterators.inc(714) : warning 202: number of arguments does not match definition
https://github.com/pawn-lang/YSI-Inc...ators.inc#L714
`addsiren` was added in the same version as actors so this should not be the problem. Check your script for `CreateVehicle` lines and count the number of parameters. Anything different than 8 (`addsiren` has a default value) or 9 is the problem.

About warning 217: loose indentation, code should be aligned properly.
pawn Code:
// wrong:
if (a == 5)
{
    a = 0;
b = 1;
}
pawn Code:
// correct:
if (a == 5)
{
    a = 0;
    b = 1;
}
Calisthenics is offline   Reply With Quote
Old 12/11/2019, 07:13 PM   #14
Th3N0oB
Big Clucker
 
Join Date: Oct 2016
Location: Ecuador
Posts: 132
Reputation: 1
Default Re: [HELP] Run time error 4: "Array index out of bounds"

Quote:
Originally Posted by Jstylezzz View Post
What the warning is trying to tell you, is that somewhere in the script there is another variable with the same name (be it within a function or global). The easiest fix would be to change the name of the variables you posted above. You can rename them with anything you see fit; Best is to choose something that will help you remember what these variables refer to exactly. If they were actors for a specific mission for example, you could call them mission01ActorId.

Also, keep in mind that arrays count from 0 That means you can start with element zero. The biggest index you can use is array size - 1 (since we count from 0), so in the case of the actor variable the highest index would be 19.
Code:
new actor[20];
actor[0] = .....
actor[1] = .....
...
actor[19] = ...
Thank you very much, solved .
Th3N0oB is offline   Reply With Quote
Old 12/11/2019, 07:17 PM   #15
Th3N0oB
Big Clucker
 
Join Date: Oct 2016
Location: Ecuador
Posts: 132
Reputation: 1
Default Re: [HELP] Run time error 4: "Array index out of bounds"

Quote:
Originally Posted by Calisthenics View Post
pawn Code:
...\pawno\include\YSI_Data\y_foreach\y_foreach_iterators.inc(714) : warning 202: number of arguments does not match definition
https://github.com/pawn-lang/YSI-Inc...ators.inc#L714
`addsiren` was added in the same version as actors so this should not be the problem. Check your script for `CreateVehicle` lines and count the number of parameters. Anything different than 8 (`addsiren` has a default value) or 9 is the problem.

About warning 217: loose indentation, code should be aligned properly.
pawn Code:
// wrong:
if (a == 5)
{
    a = 0;
b = 1;
}
pawn Code:
// correct:
if (a == 5)
{
    a = 0;
    b = 1;
}
Great, I added what was missing: "addsiren" to the default value of "0" but, the warning continues, of the YSI, only that remains to be fixed, what could it be ?, in the YSI that function is as for the actors or something similar, however in the code of the gamemode, I do not have any actor inside a vehicle with the variable "CreateVehicle" only with "AddStaticVehicle" are already 4 trains and 1 bus, but do not use CreateVehicle, if not AddStaticVehicle.
Th3N0oB is offline   Reply With Quote
Old 12/11/2019, 07:19 PM   #16
Th3N0oB
Big Clucker
 
Join Date: Oct 2016
Location: Ecuador
Posts: 132
Reputation: 1
Default Re: [HELP] Run time error 4: "Array index out of bounds"

PD: Now the gamemode has a size of 17,585 Kb (before it only had a size of around 3 Mb) I don't know what I played, this is from yesterday.
Th3N0oB is offline   Reply With Quote
Old 12/11/2019, 07:34 PM   #17
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 755
Reputation: 147
Default Re: [HELP] Run time error 4: "Array index out of bounds"

The problem is in the script. YSI hooks the function so it happens to report it first.

They are not related, it only checks if actors are defined to make sure the version is 0.3.7 and add the extra parameter. Try again CTRL + F and search for CreateVehicle. Post any line you find here.

Before you include YSI:
pawn Code:
#define YSI_YES_HEAP_MALLOC
Reference: https://github.com/pawn-lang/YSI-Inc...oc_warning.inc
Calisthenics is offline   Reply With Quote
Old 12/11/2019, 08:07 PM   #18
Th3N0oB
Big Clucker
 
Join Date: Oct 2016
Location: Ecuador
Posts: 132
Reputation: 1
Default Re: [HELP] Run time error 4: "Array index out of bounds"

Quote:
Originally Posted by Calisthenics View Post
The problem is in the script. YSI hooks the function so it happens to report it first.

They are not related, it only checks if actors are defined to make sure the version is 0.3.7 and add the extra parameter. Try again CTRL + F and search for CreateVehicle. Post any line you find here.

Before you include YSI:
pawn Code:
#define YSI_YES_HEAP_MALLOC
Reference: https://github.com/pawn-lang/YSI-Inc...oc_warning.inc
This is the format I am using in almost all scripts:

pawn Code:
autos[playerid] = CreateVehicle(modelo,1656.1246,-1883.6947,13.1237,359.9166,color1,color2,-1,0);

The only one that changes one of its values, is the one that is related to the database, to load the cars inside the server, and it is this line, with the value of "900":

pawn Code:
CreateVehicle(VehiculosInfo[i][vmodelo], VehiculosInfo[i][vx], VehiculosInfo[i][vy], VehiculosInfo[i][vz], VehiculosInfo[i][va], VehiculosInfo[i][vcolor1], VehiculosInfo[i][vcolor2], 900,0);
Th3N0oB is offline   Reply With Quote
Old 12/11/2019, 08:13 PM   #19
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 755
Reputation: 147
Default Re: [HELP] Run time error 4: "Array index out of bounds"

Can you open a_vehicles.inc file and check how many parameters `CreateVehicle` function has? An outdated file would likely cause the warning.
Calisthenics is offline   Reply With Quote
Old 12/11/2019, 08:15 PM   #20
Th3N0oB
Big Clucker
 
Join Date: Oct 2016
Location: Ecuador
Posts: 132
Reputation: 1
Default Re: [HELP] Run time error 4: "Array index out of bounds"

Quote:
Originally Posted by Calisthenics View Post
Can you open a_vehicles.inc file and check how many parameters `CreateVehicle` function has? An outdated file would likely cause the warning.
Yes, I did that quickly just now, to rule out some outdating, but they do have the parameters that it should.

pawn Code:
/*  SA-MP Vehicle Functions
 *
 *  (c) Copyright 2005-2012, SA-MP Team
 *
 */


#if defined _vehicles_included
    #endinput
#endif
#define _vehicles_included
#pragma library vehicles

#define CARMODTYPE_SPOILER      0
#define CARMODTYPE_HOOD         1
#define CARMODTYPE_ROOF         2
#define CARMODTYPE_SIDESKIRT    3
#define CARMODTYPE_LAMPS        4
#define CARMODTYPE_NITRO        5
#define CARMODTYPE_EXHAUST      6
#define CARMODTYPE_WHEELS       7
#define CARMODTYPE_STEREO       8
#define CARMODTYPE_HYDRAULICS   9
#define CARMODTYPE_FRONT_BUMPER 10
#define CARMODTYPE_REAR_BUMPER  11
#define CARMODTYPE_VENT_RIGHT   12
#define CARMODTYPE_VENT_LEFT    13

#define VEHICLE_PARAMS_UNSET    -1
#define VEHICLE_PARAMS_OFF      0
#define VEHICLE_PARAMS_ON       1

// Vehicle
native CreateVehicle(vehicletype, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay, addsiren=0);
native DestroyVehicle(vehicleid);
native IsVehicleStreamedIn(vehicleid, forplayerid);
native GetVehiclePos(vehicleid, &Float:x, &Float:y, &Float:z);
native SetVehiclePos(vehicleid, Float:x, Float:y, Float:z);
native GetVehicleZAngle(vehicleid, &Float:z_angle);
native GetVehicleRotationQuat(vehicleid, &Float:w, &Float:x, &Float:y, &Float:z);
native Float:GetVehicleDistanceFromPoint(vehicleid, Float:X, Float:Y, Float:Z);
native SetVehicleZAngle(vehicleid, Float:z_angle);
native SetVehicleParamsForPlayer(vehicleid,playerid,objective,doorslocked);
native ManualVehicleEngineAndLights();
native SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
native GetVehicleParamsEx(vehicleid, &engine, &lights, &alarm, &doors, &bonnet, &boot, &objective);
native GetVehicleParamsSirenState(vehicleid);
native SetVehicleParamsCarDoors(vehicleid, driver, passenger, backleft, backright);
native GetVehicleParamsCarDoors(vehicleid, &driver, &passenger, &backleft, &backright);
native SetVehicleParamsCarWindows(vehicleid, driver, passenger, backleft, backright);
native GetVehicleParamsCarWindows(vehicleid, &driver, &passenger, &backleft, &backright);
native SetVehicleToRespawn(vehicleid);
native LinkVehicleToInterior(vehicleid, interiorid);
native AddVehicleComponent(vehicleid, componentid);
native RemoveVehicleComponent(vehicleid, componentid);
native ChangeVehicleColor(vehicleid, color1, color2);
native ChangeVehiclePaintjob(vehicleid, paintjobid);
native SetVehicleHealth(vehicleid, Float:health);
native GetVehicleHealth(vehicleid, &Float:health);
native AttachTrailerToVehicle(trailerid, vehicleid);
native DetachTrailerFromVehicle(vehicleid);
native IsTrailerAttachedToVehicle(vehicleid);
native GetVehicleTrailer(vehicleid);
native SetVehicleNumberPlate(vehicleid, numberplate[]);
native GetVehicleModel(vehicleid);
native GetVehicleComponentInSlot(vehicleid, slot); // There is 1 slot for each CARMODTYPE_*
native GetVehicleComponentType(component); // Find CARMODTYPE_* for component id
native RepairVehicle(vehicleid); // Repairs the damage model and resets the health
native GetVehicleVelocity(vehicleid, &Float:X, &Float:Y, &Float:Z);
native SetVehicleVelocity(vehicleid, Float:X, Float:Y, Float:Z);
native SetVehicleAngularVelocity(vehicleid, Float:X, Float:Y, Float:Z);
native GetVehicleDamageStatus(vehicleid, &panels, &doors, &lights, &tires);
native UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, tires);

#define VEHICLE_MODEL_INFO_SIZE             1
#define VEHICLE_MODEL_INFO_FRONTSEAT        2
#define VEHICLE_MODEL_INFO_REARSEAT         3
#define VEHICLE_MODEL_INFO_PETROLCAP        4
#define VEHICLE_MODEL_INFO_WHEELSFRONT      5
#define VEHICLE_MODEL_INFO_WHEELSREAR       6
#define VEHICLE_MODEL_INFO_WHEELSMID        7
#define VEHICLE_MODEL_INFO_FRONT_BUMPER_Z   8
#define VEHICLE_MODEL_INFO_REAR_BUMPER_Z    9

native GetVehicleModelInfo(vehiclemodel, infotype, &Float:X, &Float:Y, &Float:Z);

// Virtual Worlds
native SetVehicleVirtualWorld(vehicleid, worldid);
native GetVehicleVirtualWorld(vehicleid);
Th3N0oB is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[debug] Run time error 4: "Array index out of bounds" problem MaestrulFritz Scripting Help 1 31/08/2019 12:14 PM
[debug] Run time error 4: "Array index out of bounds" nGen.SoNNy Scripting Help 3 06/03/2019 05:16 PM
Run time error 4: "Array index out of bounds" in Server Console! HAGAKURE Scripting Help 6 13/07/2016 10:18 PM
[debug] Run time error 4: "Array index out of bounds" and many more errors :P ntmp Scripting Help 2 11/08/2014 03:10 PM
Run time error 4: "Array index out of bounds" in public turftaking [SF]OutLawZ Scripting Help 1 01/08/2012 06:07 AM


All times are GMT. The time now is 03:18 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.