SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 26/09/2013, 03:44 PM   #1
damian123
Big Clucker
 
Join Date: Aug 2013
Posts: 56
Reputation: 6
Default Error 022: lvalue is not constant

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;
}
damian123 is offline   Reply With Quote
Old 26/09/2013, 04:46 PM   #2
Blast3r
Banned
 
Join Date: Aug 2011
Location: Croatia, Knin
Posts: 632
Reputation: 115
Default Re: Error 022: lvalue is not constant

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).
Blast3r is offline   Reply With Quote
Old 26/09/2013, 04:52 PM   #3
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,828
Reputation: 1401
Default Re: Error 022: lvalue is not constant

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.
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 26/09/2013, 05:04 PM   #4
damian123
Big Clucker
 
Join Date: Aug 2013
Posts: 56
Reputation: 6
Default Re: Error 022: lvalue is not constant

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.
damian123 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error 022: must be lvalue (non-constant) Jstylezzz Scripting Help 3 20/07/2012 09:50 PM
error 022: must be lvalue (non-constant) BLAbla93 Scripting Help 3 07/03/2012 07:22 AM
error 022: must be lvalue (non-constant) kiloman3 Scripting Help 2 23/11/2011 11:10 AM
error 022: must be lvalue (non-constant) [SF]OutLawZ Help Archive 5 25/12/2010 04:00 AM
error 022: must be lvalue (non-constant) DiddyBop Help Archive 3 03/09/2010 07:14 PM


All times are GMT. The time now is 10:38 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.