Jump to content
Sign in to follow this  
peeps

setvariable & getvariable

Recommended Posts

Hey guys. Im really struggling to create a variable on each player on a server.

I've used this command :

player setvariable ["hasbomb", false, false];

which I think creates a bool value on the player called hasbomb and sets it to false.

I then try to retrieve the value later using :

_canplant = _playertoplant getvariable "hasbomb";

(_playertoplant is referring to a player). I then attempt to use _canplant in an if statement..

if (_canplant = true) then {

//blahblahblah

};

However I get an error saying a bool was expected but an array was given.

Can someone explain what im doing wrong here?

Share this post


Link to post
Share on other sites

Did you try:

_canplant = _playertoplant getvariable ["hasbomb", 0];

Second thing is, in if-statements you have to use == to check a condition. = is for assigning:

if (_canplant == true)

Share this post


Link to post
Share on other sites
player setVariable ["hasbomb",0,true];

if (_playertoplant getvariable "hasbomb" == 1) then {bla bla bla};

Share this post


Link to post
Share on other sites

thanks guys, works now :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×