Error 022: lvalue is not constant
#1

pawn Code:
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;
}
Reply
#2

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).
Reply
#3

Quote:
Originally Posted by Blast3r
View Post
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.
Reply
#4

Quote:
Originally Posted by Blast3r
View Post
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).
pawn Code:
target = v;
This one.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)