Array index out of bounds
#1

Hey guys. Firstly, Thanks for looking at the thread. Secondly: The issue I'm having is when I try to load player cars. I'm getting an error that says "error 032: array index out of bounds (variable "CarInfo")". I honestly have no idea whats causing this, as the first line works, but any subsequent line reaching for the enum says it out of bounds.

Heres the problem code

Код:
	for(new i = 0; i < rows; i++) // run the for loop for how ever many cars are returned, should be less then or equal to 5.
	{
	//"SELECT cID, cModel, cCol1, cCol2, cPlate, cInsured, cHealth, cPosX, cPosY, cPosZ, cPosR, cPanelDamage, cDoorDamage, cLightDamage, cTireDamage, cMileage, cFuel, cFuelType, cEngineToggleable, cDoors FROM `cinfo` WHERE cOwner = '%s'", playerName);
		lolcar = CreateVehicle(400, 0, 0, -5, 0, 0, 0, 60000);
		cache_get_row(i, 0, temp); CarInfo[lolcar][cId] = strval(temp); //This one works
		PlayerInfo[playerid][pCarsOwned] = rows;
		cache_get_row(i, 1, temp); CarInfo[lolcar][cModel] = strval(temp);//So does this one...
		cache_get_row(i, 2, temp); CarInfo[lolcar][cCol1] = strval(temp); //none of these works, past those two.
		cache_get_row(i, 3, temp); CarInfo[lolcar][cCol2] = strval(temp);
		cache_get_row(i, 7, temp); CarInfo[lolcar][cPosX] = floatstr(temp);
		cache_get_row(i, 8, temp); CarInfo[lolcar][cPosY] = floatstr(temp);
		cache_get_row(i, 9, temp); CarInfo[lolcar][cPosZ] = floatstr(temp);
		cache_get_row(i, 10, temp); CarInfo[lolcar][cPosR] = floatstr(temp);
		DestroyVehicle(lolcar);
		lolcar = CreateVehicle(CarInfo[lolcar][cModel], CarInfo[lolcar][cPosX], CarInfo[lolcar][cPosY], CarInfo[lolcar][cPosZ], CarInfo[lolcar][cPosR], CarInfo[lolcar][cCol1], CarInfo[lolcar][cCol2], 60000);
		GetPlayerName(playerid, CarInfo[lolcar][cOwner], MAX_PLAYER_NAME);
		cache_get_row(i, 4, CarInfo[lolcar][cPlate]); SetVehicleNumberPlate(lolcar, CarInfo[lolcar][cPlate]); //Get the plate, and stick it onto the car
		cache_get_row(i, 5, temp); CarInfo[lolcar][cInsured] = strval(temp); //Is the car insured???
		cache_get_row(i, 6, temp); CarInfo[lolcar][cHealth] = floatstr(temp); SetVehicleHealth(lolcar, CarInfo[lolcar][cHealth]);//Get the health of the car, then set it.
		cache_get_row(i, 11, temp); CarInfo[lolcar][cPanelDamage] = strval(temp); //Panel damage of the vehicle.
		cache_get_row(i, 12, temp); CarInfo[lolcar][cDoorDamage] = strval(temp); // Get the door damage
		cache_get_row(i, 13, temp); CarInfo[lolcar][cLightDamage] = strval(temp); //Get the light damage
		cache_get_row(i, 14, temp); CarInfo[lolcar][cTireDamage] = strval(temp); // Get the tire damage
		cache_get_row(i, 15, temp); CarInfo[lolcar][cMileage] = strval(temp); //Get the Mileage of the car.
		cache_get_row(i, 16, temp); CarInfo[lolcar][cFuel] = strval(temp);//How much gas is in the car?
		cache_get_row(i, 17, temp); CarInfo[lolcar][cFuelType] = strval(temp);//How much diesel is in the car??
		cache_get_row(i, 18, temp); CarInfo[lolcar][cEngineToggleable] = strval(temp);
		cache_get_row(i, 19, temp); CarInfo[lolcar][cLocked] = strval(temp);
		new string[128];
		format(string, sizeof(string), "Car is locked = %i, %s", CarInfo[lolcar][cLocked], temp);
		SendClientMessage(playerid, -1, string);
		CarInfo[lolcar][cEngineToggleable] = 1; // Car can be turned on...-at this point-
		PlayerInfo[playerid][pCarsSpawned][i] = lolcar; //Add this car to their list of spawned cars!
		UpdateVehicleDamageStatus(lolcar, CarInfo[lolcar][cPanelDamage], CarInfo[lolcar][cDoorDamage], CarInfo[lolcar][cLightDamage], CarInfo[lolcar][cTireDamage]); // Set the damage
		SetVehicleParamsEx(lolcar, 0,  0,  0,  CarInfo[lolcar][cLocked], 0, 0, 0);
	}
Here's the enum for the cars.

Код:
enum cInfo //Car Enumator
{
	cId,
	cModel,
	cCol1,
	cCol2,
	cOwner[MAX_PLAYER_NAME],
	cFaction, // if cFaction == 1, it's in a faction...see car owner for faction of car.
	cPlate,
	cInsured,
	cPanelDamage,
	cDoorDamage,
	cLightDamage,
	cTireDamage,
	cLocked,
	Float:cHealth,
	Float:cPosX,
	Float:cPosY,
	Float:cPosZ,
	Float:cPosR,
	cEngine,
	cAlarm,
	cLights,
	cDoors,
	cBonnet,
	cBoot,
	cObjective,
	cWeed,
	cCocaine,
	cHeroin,
	cMDMA,
	cWeapons,
	cAmmo,
	cFuel,
	cFuelType,
	cMileage,
	cFuelTimer,
	cFuelTDTimer,
	cDriver,
	cTick,
	cEngineToggleable,
	cWindows = 0,
	cRadio,
}
new CarInfo[MAX_VEHICLES][cInfo];
Thanks for any help.
Reply
#2

The error is happening because after that first instance of CreateVehicle with lolcar, it bumps the integer value of lolcar up by one and that appears to be out of that array's size. You could try redefining MAX_VEHICLES to something a bit higher and see if that works.
Reply
#3

That didn't do anything. Same problem. I didn't think that'd be the case as it would only appear after I've destroyed the vehicle. This is stumping me simply because the first two lines work, but then the array is out of bounds? Why is that. I'm also assuming that lolcar is the problem, not cInfo. I might be wrong though.
Reply
#4

Hate to be that guy, but bump.
Reply
#5

One more bump...
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)