SA-MP Forums Archive
error 022: 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)
+--- Thread: error 022: must be lvalue (non-constant) (/showthread.php?tid=474968)



error 022: must be lvalue (non-constant) - Voxel - 10.11.2013

Can some one explain me how do i get the players money and score and put them in the database?
i am using konstatinos sqlite tutorial...

errors:
pawn Код:
(372) : error 022: must be lvalue (non-constant)
(376) : error 022: must be lvalue (non-constant)
pawn Код:
USER_MONEY = GetPlayerMoney(playerid); //372
db_get_field_assoc(Result, "money", Query, 20);
User[playerid][USER_MONEY] = strval(Query);
                   
USER_SCORE = GetPlayerScore(playerid); //376
db_get_field_assoc(Result, "score", Query, 100);
User[playerid][USER_SCORE] = strval(Query);
I read the tutorial completely but i dont understand it.


Re: error 022: must be lvalue (non-constant) - Konstantinos - 10.11.2013

USER_MONEY and USER_SCORE are indexes of the enum so you cannot use it like that.

Also lines 372 and 376 are not needed at all because all you want to do is load the money and score the the database - therebefore, getting the money/score is useless.


Re: error 022: must be lvalue (non-constant) - Ada32 - 10.11.2013

pawn Код:
User[playerid][USER_MONEY] = GetPlayerMoney(playerid);

User[playerid][USER_SCORE] = GetPlayerScore(playerid); //376



Re: error 022: must be lvalue (non-constant) - Jefff - 10.11.2013

pawn Код:
enum OMGx2
{
    USER_MONEY,
    USER_SCORE
};
new User[MAX_PLAYERS][OMGx2];

db_get_field_assoc(Result, "money", Query, 20);
User[playerid][USER_MONEY] = strval(Query);

db_get_field_assoc(Result, "score", Query, 100);
User[playerid][USER_SCORE] = strval(Query);



Re: error 022: must be lvalue (non-constant) - Voxel - 10.11.2013

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
USER_MONEY and USER_SCORE are indexes of the enum so you cannot use it like that.

Also lines 372 and 376 are not needed at all because all you want to do is load the money and score the the database - therebefore, getting the money/score is useless.
So i want it to be like the rest.. like when you get money in game it saves to the database etc... where and what am i suposed to do?


Re: error 022: must be lvalue (non-constant) - Konstantinos - 10.11.2013

Quote:
Originally Posted by Voxel
Посмотреть сообщение
So i want it to be like the rest.. like when you get money in game it saves to the database etc... where and what am i suposed to do?
When a player disconnects (OnPlayerDisconnect), you execute a query about updating the data.

pawn Код:
format( Query, sizeof( Query ), "UPDATE users SET money = %d, score = %d WHERE username = '%s'", GetPlayerMoney( playerid ), GetPlayerScore( playerid ), DB_Escape( User[ playerid ][ USER_NAME ] ) );
db_query( Database, Query );
If you use server-side money, then replace GetPlayerMoney with the one you store the money.


Re: error 022: must be lvalue (non-constant) - Voxel - 10.11.2013

Thank you ! gonna try it.


Re: error 022: must be lvalue (non-constant) - Voxel - 10.11.2013

It works! ty Konstantinos!!