Global variables

Merg

Well-Known Member
So im trying to check a variable that is defined in the server.pbo and checked in the mission folder.

server.pbo:

myGlobalVar = true;

Mission folder:

If(myGlobalVar) then{};


But the rpt says that the variable is undefined.

Does anyone know what im doing wrong?
 
To expand on the previous link:

Each computer only knows about variables that are defined on itself. To get a variable to be defined on the Server and then have all the computers (clients) be updated with its value you need to use the publicvariable statement which actually transmits that variable and its value to all the connected computers.

You might also need to use a publicvariable event handler which will trigger a bit of code whenever that publicvariable is broadcast .. like when it changes from false to true.
https://community.bistudio.com/wiki/addPublicVariableEventHandler

So you would use
globalvariable = true;
publicvariable "globalvariable";
... its now been sent to all other computers and you can refer to it. If your client code runs before the server code has sent the variable it will be nil and your code won't work as expected which is where the event handlers come in handy.
 
You can also do more advanced things like change the value of the pubvar between the client and the server with the PublicVariableServer & PublicVariableClient commands :)
 
Back
Top