Code doesn't work.
#1

Hello.

I have a strange problem, namely the code I put below doesn't work.

Код:
new string[100], vehicleid[2], VehicleText[30];
vehicleid[0] = dini_Int(PlayerAccountPath(playerid), "PrivVeh1");
vehicleid[1] = dini_Int(PlayerAccountPath(playerid), "PrivVeh2");
PlayerData[PlayerData[playerid][SellID]][SellAmount] = strval(inputtext);
PlayerData[PlayerData[playerid][SellID]][SellID] = playerid;
if(PlayerData[playerid][VehicleSell] == 1)
{
	strcat(VehicleText, VehicleNames[vehicleid[0] -400]);
	PlayerData[PlayerData[playerid][SellID]][VehicleSell] = 1;
}
else
{
	strcat(VehicleText, VehicleNames[vehicleid[1] -400]);
	PlayerData[PlayerData[playerid][SellID]][VehicleSell] = 2;
}
CrashDetect detects that:

Код:
[debug] Run time error 4: "Array index out of bounds"
[18:42:59] [debug]  Attempted to read/write array element at negative index -400
[18:42:59] [debug] AMX backtrace:
[18:42:59] [debug] #0 000158f4 in public OnDialogResponse (0, 94, 1, -1, 2249876) from carriage.amx
I am asking you for help.
Reply
#2

Looks like vehicleid[0] or vehicleid[1] have the value 0, since you subtract 400 from it and it accesses index -400 which is invalid:

Код:
strcat(VehicleText, VehicleNames[vehicleid[0] -400]);
You should check if the values were successfully loaded before accessing an array with them.

Also, is it a Vehicle ID or a Model ID? Since Models start at 400, and Vehicle IDs at 1. So either way, the ID is invalid.
Reply
#3

I had this error in my gamemode too and solved by this
Код:
VehicleNames[GetVehicleModel(vehicleid[0])-400]);
VehicleNames[GetVehicleModel(vehicleid[1])-400]);
you are trying to get the vehicle name from a model id
Reply
#4

Thanks. It helped.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)