Jump to content
Sign in to follow this  
Fuzzy Bandit

Getting the Value of a Variable

Recommended Posts

Hello!

In my current script, there are global variables initialised in the init.sqf. These are:

uspoints = 0;
plapoints = 0;
tflag1 = "Neutral";
tflag2 = "Neutral";
tflag3 = "Neutral";

Now everything works fine as long as all players join before the game starts. If a player joins the game while it's in progress, however, their variable values are set to the default ones in the init.sqf.

For example, uspoints may have changed (and updated to all machines using publicVariable) to 30. Then the new player joins, and for that player uspoints is set to 0.

Same goes for all the other variables.

Now, is there any way to make it so that the player grabs updated versions of these variables upon entering the game? If so, how?

I've tried the getVariable command in the unit's init box, and it didn't seem to work at all. Variables still came back as 0.

Any ideas folks?

Cheers!

Share this post


Link to post
Share on other sites

Check if variable is nil:

if (isNil "uspoints") then {uspoints = 0};

if (isNil "plapoints") then {plapoints = 0};

Share this post


Link to post
Share on other sites

But what if (most likely) it isn't nil?

---------- Post added at 02:24 ---------- Previous post was at 02:20 ----------

Nevermind, just been reading up and it seems the answer is to define variables in Game Logics rather than in init.sqf.

Share this post


Link to post
Share on other sites

Or you could init and pubvar the variables from server.

if (isserver) then {
 uspoints = 0; publicvariable "uspoints";
 plapoints = 0; publicvariable "plapoints";
 tflag1 = "Neutral"; publicvariable "tflag1";
 tflag2 = "Neutral"; publicvariable "tflag2";
 tflag3 = "Neutral"; publicvariable "tflag3";
};

That way nothing gets overwritten and correct values are synced to JIPs etc.

Share this post


Link to post
Share on other sites

Good point!

Very nice alternative - I find it much nicer to have all the variables laid out in the init.sqf!

Share this post


Link to post
Share on other sites
But what if (most likely) it isn't nil?

Then the client will recieve the variable from the server which was broadcasted with publicVariable.

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  

×