variable
#1

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?
Reply
#2

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

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];
Reply
#4

"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.
Reply
#5

derp my English isn't that well and i don't understand all the mentioned terms, thanks once again Vince, you saved the day.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)