Page tree
Skip to end of metadata
Go to start of metadata

Introduced in




Broadcast the value of a given variable to all computers in a multiplayer scenario.

The following Category Data Types are supported in VBS:

Note: References to entities which are local, such as Script, Display, or local objects, cannot be transferred using this command.


Syntax:publicVariable "varName"
  • varName: String - Variable name, enclosed in quotation marks.
Return Value:Nothing


Examples:publicVariable "CTFscoreOne"

Additional Information

See also: addPublicVariableEventHandler
Multiplayer:The message is sent consequently and reliably to all clients. Using publicVariable too frequently in a given period of time can cause other parts of the game to experience bandwidth problems.


Posted 2007
This command broadcasts a variable to all clients, but as soon as you change the variable again, you have to use publicVariable again, as it does not automatically synchronise it.

Posted on 2 Feb, 2008
When initialising a public variable to handle JIP, you will usually first want to check if the public variable has already been (broadcast, received and) set locally. Otherwise you may inadvertantly overwrite the broadcast value with your default value.

To perform this check, use code similar to the following to first check that the variable is nil:

if (isNil "PV_abc") then
  // set the nil variable with a default value for server and both JIP & 'join at mission start' 
  PV_abc = [7, 8, 9]; 
// else public variable has already been set due to a public variable broadcast.