Jump to content
Sign in to follow this  
Luft08

publicVariable not public??

Recommended Posts

On my server I have the code:

spotterChance = floor random 100;
publicVariable "spotterChance";

I wish to push the spotterChance value to the clients but when I call the following function it throws an "undefined variable" error:

private _satReliability = "working well.";
if(spotterChance < 91) then {_satReliability = "fairly good.";};
if(spotterChance < 76) then {_satReliability = "spotty.";};
if(spotterChance < 51) then {_satReliability = "flaky today.";};
if(spotterChance < 21) then {_satReliability = "nearly down.";};

_satReliability

 

Share this post


Link to post
Share on other sites

Depending on which scripts you have running the code, it could be an Order of Initialization issue:

 

- In single player, the init.sqf runs before the initServer.sqf, initPlayerLocal.sqf and the initPlayerServer.sqf.  But in multiplayer init.sqf runs last of all.

- In all cases, Server runs the initServer, but joined Clients don't.

- While Server runs the initServer, the joined Clients instead run initPlayerLocal.

- After these,  a hosted Server runs initPlayerLocal for the host player.

- The Server then runs the initPlayerServer as players join.

- All these run in scheduled environment, which can also effect timing, as it gets impacted by the workload.

 

So it depends on what is run before the other.  It's possible that Clients call the _satReliability function while Server is still doing its own initializing, and they  have not yet received the publicVariable.  In which case you could wait for spotterChance to be defined on client before having client call the function.

Edited by opusfmspol
  • Like 1

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  

×