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(playerid, params[])
{
PlayerData[playerid][WantedLevel] = 5;
format(str,sizeof(str),"wanted level is %d",PlayerData[playerid][WantedLevel]);
SCM(playerid, adminchat, str);
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(playerid, params[])
{
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(playerid, params[])
{
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(playerid, params[])
{
switch(PlayerData[playerid][WantedLevel]) { case 5: return SCM(playerid, red, "Good"); }
return 1;
}
Re : Local variable not saving -
Dutheil - 13.04.2015
@Azula : Use "switch" in such case is totally useless.