Jump to content
Sign in to follow this  
wowanno

Weird behaviour setvar getvar clients server

Recommended Posts

I have a file which executes on clients only via init.sqf using if(!isDedicated) then {execVM "clienttest.sqf";}.

In this file, I run the following:

player setVariable["myTestVar", 1, true]; (I tried using false here as well, just to see what happens).

On startup, server executes a file called servertest.sqf. In this file, the following loop is executed:

{

...

_x setVariable["myTestVar2", 1, true];

...

}foreach playableUnits;

Server also executes one more file, this time using the following:

if(isPlayer (_x)) then ...

...

_result= _x getVariable "myTestVar";

_result2= _x getVariable "myTestVar2";

Question:

This works sometimes. Sometimes nothing is loaded, sometimes everything is loaded, sometimes only 1 variable is loaded.

Why?

What I want to do here is assign variables to player objects via setVariable. Later on, I want to access these variables from the server by calling getVariable (hardcoded names) on every client. Further, I want the server to be able to overwrite these variables (again, names hardcoded) via setVariable.

Is such thing possible? If so, what is the proper way to go about it?

Edited by wowanno
formatting

Share this post


Link to post
Share on other sites

If one of your scripts is dependant on a set variable to any object, you should check if the variable was set already as it could take some time until the variable value is synchronized with every client.

Using a default value and waitUntil, you can cook together something like this:

_myObject setVariable ["myVariable", 10, true];

waitUntil {_myObject getVariable ["myVariable", -1] != -1};
_value = _myObject getVariable "myVariable";

Share this post


Link to post
Share on other sites

Thank you for your reply XxAnimusxX. This seems like a good idea. Cheers!

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  

×