Array index out of bounds
#1

I have this command:

Код:
new SelVeh[MAX_PLAYERS][10];

CMD:myvehicles(playerid)
{
	new string[256], count = 0;
	if(CountUserVehicle(playerid) == 0) return SS(playerid, COOL_GREEN, "You don't own any vehicles.", "Nu detii nici o masina.");
	DeletePVar(playerid, "selected_vehicle");
	format(string, sizeof(string), "Name\tStatus\tCarplate\tPrice\n");
	for(new i = 0; i < sizeof(vehicleVariables); i++)
	{
		if(vehicleVariables[i][vVehicleOwnerID] == playerVariables[playerid][pInternalID])
		{
			SelVeh[playerid][count] = vehicleVariables[i][vVehicleID];
			if(vehicleVariables[i][vVehicleStatus] == 0) format(string, sizeof(string), "%s%s\t{%s}[ despawned ]\t%s\t$%s\n", string, VehicleNames[vehicleVariables[i][vVehicleModelID] - 400], selColor[175], vehicleVariables[i][vVehicleNumber], NumberFormat(vehPrice[vehicleVariables[i][vVehicleModelID]]));
			else format(string, sizeof(string), "%s%s\t{%s}[ spawned ]\t%s\t$%s\n", string, VehicleNames[vehicleVariables[i][vVehicleModelID] - 400], selColor[226], vehicleVariables[i][vVehicleNumber], NumberFormat(vehPrice[vehicleVariables[i][vVehicleModelID]]));
			count++;
		}
	}
	ShowPlayerDialog(playerid, DIALOG_DISPLAY_VEHICLES, DIALOG_STYLE_TABLIST_HEADERS, "SERVER: Your Vehicles", string, "Select", "Cancel");
	return 1;
}
Which displays your owned vehicles on the server.
Now whenever I use that command, the dialog works fine, but when I click on the vehicle, I get the error "Array index out of bounds".
This is the dialog response code:

Код:
	if(dialogid == DIALOG_DISPLAY_VEHICLES)
	{
		if(response)
		{
			new x = SelVeh[playerid][listitem];
			SpawnVehicleIfDespawned(x);
			SetPVarInt(playerid, "selected_vehicle", GrabVID(x));
			printf("GrabVID: %d", GrabVID(x));
			format(szMessage, sizeof(szMessage), "%s (%d)", VehicleNames[vehicleVariables[GrabVID(x)][vVehicleModelID] - 400], x);
			ShowPlayerDialog(playerid, DIALOG_VEHICLE_INFO, DIALOG_STYLE_LIST, "test", "Respawn Vehicle\nFind Vehicle\nSet Carplate\nPay Insurance\nSet Price\nUnstuck Vehicle\n{FFD738}Upgrade to VIP{FFFFFF}", "Select", "Cancel");
		}
	}
That is where I get that error.

This is the GrabVID stock:

Код:
stock GrabVID(x)
{
	for(new i = 0; i < MAX_VEHICLES; i++)
	{
		if(vehicleVariables[i][vVehicleID] == x) return i;
	}
	return INVALID_VEHICLE_ID;
}
Reply
#2

vehicleVariables[i][vVehicleID] can you show the place where you created this variable?
Reply
#3

Try to replace MAX_VEHICLES in GrabVID functions, with sizeof(vehicleVariables).
Код:
stock GrabVID(x)
{
	for(new i = 0, j = sizeof(vehicleVariables); i < j; i++)
	{
		if(vehicleVariables[i][vVehicleID] == x) return i;
	}
	return INVALID_VEHICLE_ID;
}
Reply
#4

Quote:
Originally Posted by AroseKhanNiazi
Посмотреть сообщение
vehicleVariables[i][vVehicleID] can you show the place where you created this variable?
No, thats the ID from the database
Reply
#5

Quote:
Originally Posted by X337
Посмотреть сообщение
Try to replace MAX_VEHICLES in GrabVID functions, with sizeof(vehicleVariables).
Код:
stock GrabVID(x)
{
	for(new i = 0, j = sizeof(vehicleVariables); i < j; i++)
	{
		if(vehicleVariables[i][vVehicleID] == x) return i;
	}
	return INVALID_VEHICLE_ID;
}
But the thing is, i want to return the vehicleid, not the enum id.
Reply
#6

I fixed it! It was a different stock that caused that problem.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)