Skip to content

publicVariable

ffredyk edited this page Jul 23, 2026 · 1 revision

publicVariable

Category

Multiplayer

Arity

UnarypublicVariable "<variableName>".

publicVariable <string>   // quoted variable name

Description

Broadcasts the value of a global variable to all connected clients (and the server). The variable name is passed as a string. After broadcast, the variable's current value is synchronized to all machines.

Placeholder/stub — full networking implementation is the host's responsibility.

Registered by DeclareMultiplayerCommands(). NOT called automatically — host must invoke explicitly.

How It Works

Fires the host's public variable broadcast event with the variable name. The host must serialize the variable's value and transmit it over the network. Target machines update their local copy of the variable.

Usage

myVar = 42;
publicVariable "myVar";        // broadcast myVar to all clients

_missionTime = 300;
publicVariable "_missionTime";

Typical pattern

// Server sets and broadcasts
if (isServer) then {
    weatherState = "clear";
    publicVariable "weatherState";
};

// Clients react to change
// (host must implement variable change events)

Note: The variable must already exist as a global before calling publicVariable.

Thread Safety

Depends on host implementation.

See Also

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally