SA-MP Forums Archive
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: Array index out of bounds (/showthread.php?tid=435747)



Array index out of bounds - Wesley221 - 08.05.2013

I have a command, which shows all the vehicles with the id, ownername, vehiclename and model. Although, im getting an error but im not sure how to fix it. The command DOES work, it shows all the vehicles, and after that you get the Unkown Command line after it.

pawn Code:
for( new j = 1; j < MAX_PERS_VEHICLES; j ++ )
    {
        new testvar[50];
        strset( testvar, aVehicleNames[VehicleInfo[j][vModel] - 400] );
        //if( VehicleInfo[i][vID] != -1 )
        //{
        format( query, sizeof query, "| CarID: %i | Owner: %s | Vehicle: %s(%i) |", VehicleInfo[j][vID], VehicleInfo[j][vOwner], testvar, VehicleInfo[j][vModel] );
        SendClientMessage( playerid, -1, query );
        printf( "i = %i, vehiclename = %s | i-vmodel = %i | vmodel = %i | VehicleInfo[%i]", j, aVehicleNames[VehicleInfo[j][vModel] - 400], ( VehicleInfo[j][vModel]-400 ), VehicleInfo[j][vModel], j );
        //}
    }
Code:
[14:12:26] i = 1, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[1]
[14:12:26] i = 2, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[2]
[14:12:26] i = 3, vehiclename = Infernus | i-vmodel = 11 | vmodel = 411 | VehicleInfo[3]
[14:12:26] i = 4, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[4]
[14:12:26] i = 5, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[5]

[14:12:26] [debug] Run time error 4: "Array index out of bounds"
[14:12:26] [debug]  Accessing element at negative index -400
[14:12:26] [debug] AMX backtrace:
[14:12:26] [debug] #0 0000c664 in public cmd_showcpv () from gm.amx
[14:12:26] [debug] #1 native CallLocalFunction () [00471e90] from samp-server.exe
[14:12:26] [debug] #2 00006118 in public OnPlayerCommandText () from gm.amx



Re: Array index out of bounds - Wesley221 - 09.05.2013

Bump


Re: Array index out of bounds - Wesley221 - 09.05.2013

The weird thing is, none of them are.
Code:
[14:12:26] i = 1, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[1]
[14:12:26] i = 2, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[2]
[14:12:26] i = 3, vehiclename = Infernus | i-vmodel = 11 | vmodel = 411 | VehicleInfo[3]
[14:12:26] i = 4, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[4]
[14:12:26] i = 5, vehiclename = NRG-500 | i-vmodel = 122 | vmodel = 522 | VehicleInfo[5]
The i-vmodel are just normal values, same with the models.


Re: Array index out of bounds - Wesley221 - 09.05.2013

Thanks, fixed the problem.

VehicleInfo[vehicleid][vID] isnt set as -1, whenever the vehicle doesnt exists.