SA-MP Forums Archive
Local variable not saving - 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: Local variable not saving (/showthread.php?tid=570776)



Local variable not saving - romas3110 - 13.04.2015

hey guys, so heres the deal. im in the middle of finishing up my /want system
the command works fine and so does the database saving, but the actual variable inside the script isnt saving to its assigned value. for example, in the code below it sets the value to 5, and when it checks if the value is 5 it returns nothing here are my enums cheers.
Код:
enum pdata
{
    WantedLevel
}
new PlayerData[MAX_PLAYERS][pdata];
Код:
CMD:test(playerid, params[])
{
    PlayerData[playerid][WantedLevel] = 5;
    return 1;
}
CMD:check(playerid, params[])
{
    if(PlayerData[playerid][WantedLevel] == 5) return SCM(playerid, red, "Good");
    return 1;
}



Re: Local variable not saving - SequenceCuz - 13.04.2015

May be try to create string in the cmd:check

and sendclientmessage to that string

that string including like this format{.....blalblabla "%i", PlayerData[playerid][WantedLevel])

and sendtheclientmessage to your id

and see what's the valve


Re: Local variable not saving - romas3110 - 13.04.2015

Alright tryed that it still said 0, although i did try this

PHP код:
CMD:check(playeridparams[])
{
    
PlayerData[playerid][WantedLevel] = 5;
    
format(str,sizeof(str),"wanted level is %d",PlayerData[playerid][WantedLevel]);
    
SCM(playeridadminchatstr);
    return 
1;

And it saved just fine. but if i do it outside of this command it doesnt work at all.


Re: Local variable not saving - NoDi522 - 13.04.2015

PHP код:
CMD:test(playeridparams[])
{
    if(
PlayerData[playerid][WantedLevel] == 5) return SendClientMessage(playerid,-1,"Your wanted level is already 5");
    else
    {
        
PlayerData[playerid][WantedLevel] = 5;
        
SendClientMessage(playerid,-1,"You wanted level is now 5");
    }
    return 
1;
}
CMD:check(playeridparams[])
{
    if(
PlayerData[playerid][WantedLevel] != 5) return SendClientMessage(playerid, -1"You can't use this command because your WL is not 5!");
    else
    {
        if(
PlayerData[playerid][WantedLevel] == 5) return SendClientMessage(playerid, -1,"You wanted level is 5");
    }
    return 
1;

If I understand you, you need something like this:


Re: Local variable not saving - Azula - 13.04.2015

PHP код:
CMD:check(playeridparams[])
{
    switch(
PlayerData[playerid][WantedLevel]) { case 5: return SCM(playeridred"Good"); }
    return 
1;




Re : Local variable not saving - Dutheil - 13.04.2015

@Azula : Use "switch" in such case is totally useless.