SA-MP Forums Archive
Must be lvalue (non-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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Must be lvalue (non-constant) (/showthread.php?tid=231635)



Must be lvalue (non-constant) - Th3Angel - 26.02.2011

pawn Код:
static const oldmoney;
oldmoney = GetPlayerMoneyEx(playerid); //Line 1258
SetPlayerMoneyEx(playerid, oldmoney);
pawn Код:
(1258) : error 022: must be lvalue (non-constant)
Still trying to figure out what it means. Can anyone explain it to me please?


Re: Must be lvalue (non-constant) - klk - 26.02.2011

const means that you cannot change oldmoney value in your code.


Re: Must be lvalue (non-constant) - Th3Angel - 26.02.2011

I know that. Before I changed it to static, it was new const and it worked fine. I mean can you explain lvalue and why it is giving that error.


Re: Must be lvalue (non-constant) - Antonio [G-RP] - 26.02.2011

From my understanding, static means 'the same'. That might be why it complains (sort of speak) when you attempt to change the value.


Re: Must be lvalue (non-constant) - Th3Angel - 26.02.2011

Quote:
Originally Posted by Antonio [G-RP]
Посмотреть сообщение
From my understanding, static means 'the same'. That might be why it complains (sort of speak) when you attempt to change the value.
Yes, but I changed it to new const and it still gives back the same error.


Re: Must be lvalue (non-constant) - Antonio [G-RP] - 26.02.2011

Howcome it isnt just new (without the const) ?


Re: Must be lvalue (non-constant) - Th3Angel - 26.02.2011

Because its in OnPlayerUpdate which is called 6-10 times per second.


Re: Must be lvalue (non-constant) - klk - 26.02.2011

Quote:

022 must be lvalue (non-constant)
The symbol that is altered (incremented, decremented, assigned
a value, etc.) must be a variable that can be modified (this kind
of variable is called an lvalue). Functions, string literals, arrays
and constants are no lvalues. Variables declared with the “const”
attribute are no lvalues either.

Код:
static const oldmoney;
oldmoney = GetPlayerMoneyEx(playerid);
Bad.

Код:
static const oldmoney = GetPlayerMoneyEx(playerid);
Good.


Re: Must be lvalue (non-constant) - Th3Angel - 26.02.2011

Quote:
Originally Posted by klk
Посмотреть сообщение
Код:
static const oldmoney;
oldmoney = GetPlayerMoneyEx(playerid);
Bad.

Код:
static const oldmoney = GetPlayerMoneyEx(playerid);
Good.
pawn Код:
error 008: must be a constant expression; assumed zero



Re: Must be lvalue (non-constant) - klk - 26.02.2011

On the same line? For me it works fine.