SA-MP Forums Archive
Error 022: lvalue is not constant - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Error 022: lvalue is not constant (/showthread.php?tid=466199)



Error 022: lvalue is not constant - damian123 - 26.09.2013

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;
}



Re: Error 022: lvalue is not constant - Blast3r - 26.09.2013

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).


Re: Error 022: lvalue is not constant - Konstantinos - 26.09.2013

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.


Re: Error 022: lvalue is not constant - damian123 - 26.09.2013

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.