Local variable not saving
#1

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;
}
Reply
#2

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
Reply
#3

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.
Reply
#4

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:
Reply
#5

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

Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)