PDA

View Full Version : Error 022: lvalue is not constant


damian123
26/09/2013, 03:44 PM
stock GetClosestCar(playerid, exception = INVALID_VEHICLE_ID) {

new
Float: Distance,
target = -1,
Float: vPos[3];

if(!IsPlayerInAnyVehicle(playerid)) GetPlayerPos(playerid, vPos[0], vPos[1], vPos[2]);
else GetVehiclePos(GetPlayerVehicleID(playerid), vPos[0], vPos[1], vPos[2]);

for(new v; v < MAX_VEHICLES; v++) if(GetVehicleModel(v) >= 400) {
if(v != exception && (target < 0 || Distance > GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]))) {
target = v;
Distance = GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]); // Before the rewrite, we'd be running GetPlayerPos 2000 times...
}
}
return target;
}

Blast3r
26/09/2013, 04:46 PM
First of all, could you tell us which is the exact line of that error, second of all, why did you put return target which is defined to -1? Return should be 0 (False) or 1 (True).

Konstantinos
26/09/2013, 04:52 PM
First of all, could you tell us which is the exact line of that error, second of all, why did you put return target which is defined to -1? Return should be 0 (False) or 1 (True).

Read the function's name, please.

GetClosestCar

It gets the closest car from a player. It returns the vehicleid, or if vehicles do not exist in the server, it returns -1.

@damian123: By the way, the distance should be less not greater.

damian123
26/09/2013, 05:04 PM
First of all, could you tell us which is the exact line of that error, second of all, why did you put return target which is defined to -1? Return should be 0 (False) or 1 (True).target = v; This one.