variable - 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: variable (
/showthread.php?tid=619137)
variable -
yvoms - 14.10.2016
How come i cant use a variable in a different command as a check?
Код:
CMD:cuff(playerid, params[])
{
new targetid;
if(sscanf(params,"u",targetid)) return SendClientMessage(playerid,-1,"{ff387a}[Admin]:{ffffff} /cuff [ID | Name]");
if(gTeam[playerid] != TEAM_COP || gTeam[playerid] == TEAM_FBI || gTeam[playerid] == TEAM_CIA || gTeam[playerid] == TEAM_ARMY) return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]: {ffffff}This command is restricted to the LEO class.");
if(stunned[targetid] = 0) return SendClientMessage(playerid, COLOR_WHITE, "You have to taze the player before you can cuff him!");
If(stunned[targetid] = 0 <-- If the player is not tazed, im setting this variable to 1 if the player is tazed and removing it when the timer has elapsed.
However its not working it gave me a warning on compiling, and ingame its not sending the client message
Says "possibly unintended assignment" on that line.
Anyone that knows a good solution for this?
Re: variable -
TheDrx - 14.10.2016
If you want to use a variable in more than one function (command) than you need to define the variable as global. The variable will be set for every function.
To define a global variable, you need to get at the top of your gamemode and give it a type, example: new myvariable = something;
Re: variable -
yvoms - 14.10.2016
ah thanks @theDrx, You really helped me out here, since this was exactly what i was looking for.
Edit:
I forgot to mention i did do this.
its defined at the top of my gamemode as
new Tazed[MAX_PLAYERS];
new Cuffed[MAX_PLAYERS];
Re: variable -
Vince - 14.10.2016
"Unintended assignment" only means that you used the assignment operator (=) where the equality operator (==) was expected; i.e. you're SETTING the variable to zero rather than checking that it IS zero.
Re: variable -
yvoms - 14.10.2016
derp my English isn't that well and i don't understand all the mentioned terms, thanks once again Vince, you saved the day.