---
name: "publicVariable"
type: command
status: ok
groups: ["Multiplayer", "Variables"]
arma3_since: "0.50"
locality: {"argument": "local", "effect": "global", "server_exec": false}
source: https://community.bistudio.com/wiki/publicVariable
revid: 343848
updated: 2023-07-26T14:57:01Z
---

# publicVariable

*Command · Multiplayer, Variables · Arma 3 v0.50 · introduced in Operation Flashpoint v1.34*

Locality: arguments **local** · effect **global**

## Description

Reliably broadcasts [missionNamespace](../commands/missionNamespace.md) variable and its **current** value to all computers (server/client).

Variables broadcast with [publicVariable](../commands/publicVariable.md) during a mission will be available to [JIP](../topics/Multiplayer_Scripting.md#join-in-progress) clients with the value they held at the time.

Such variables are persistent and sent to the JIP client before the first batch of client-side [Event Scripts](../topics/Event_Scripts.md) (such as [init.sqf](../topics/Event_Scripts.md)) is run.

> [!IMPORTANT]
> Using [publicVariable](../commands/publicVariable.md) too frequently and/or with a lot of data can cause other aspects of the game to experience bandwidth problems.

The following Data Types are supported:

|  |  |  |  |  |  |  |  |  |  |  |
|---|---|---|---|---|---|---|---|---|---|---|
| Type | [Number](../topics/Number.md) | [Boolean](../topics/Boolean.md) | [Object](../topics/Object.md) | [Group](../topics/Group.md) | [String](../topics/String.md) | [Text](../topics/Structured_Text.md) | [Array](../topics/Array.md) | [Code](../topics/Code.md) | [Nothing](../topics/Nothing.md) ([nil](../commands/nil.md)) | [HashMap](../topics/HashMap.md) |
| Since | Operation Flashpoint v1.34 | Armed Assault v1.00 | Armed Assault v1.09 | Arma 3 v1.26 | Arma 3 v2.02 |  |  |  |  |  |

> [!IMPORTANT]
> It is not possible (and illogical) to transfer a local entity reference, such as [scripts](../topics/Script_Handle.md), [displays](../topics/Display.md) or [local objects](../commands/createVehicleLocal.md).
>
> Also, note that [Team Member](../topics/Team_Member.md) is not supported.

## Syntax

```sqf
publicVariable varName
```

**Parameters:**

- `varName`: [String](../topics/String.md) - the [global variable](../topics/Variables.md#global-scope)'s [Identifier](../topics/Identifier.md)

**Returns:** [Nothing](../topics/Nothing.md)

## Examples

### Example 1

```sqf
TAG_MyPublicVariable = 0;
TAG_MyPublicVariable = 1;
publicVariable "TAG_MyPublicVariable";    // other clients will receive the "TAG_MyPublicVariable" variable with a 1 value

TAG_MyPublicVariable = 2;                // needs to be broadcast again - synchronisation is not automatic
```

### Example 2

JIP example:

```sqf
if (isNil "TAG_CurrentTarget") then    // has the variable already been set and broadcast?
{
    TAG_CurrentTarget = objNull;    // if not, set it on the local machine
};

player doTarget TAG_CurrentTarget;
```

### Example 3

```sqf
TAG_BossName = "EvilBigBoss";

publicVariable TAG_BossName;    // wrong - will try to publicVariable "EvilBigBoss" variable, that does not exist
publicVariable "TAG_BossName";    // correct - important, do not forget the QUOTES
```

## See also

[Multiplayer Scripting](../topics/Multiplayer_Scripting.md) · [Initialisation Order](../topics/Initialisation_Order.md) · [addPublicVariableEventHandler](../commands/addPublicVariableEventHandler.md) · [publicVariableClient](../commands/publicVariableClient.md) · [publicVariableServer](../commands/publicVariableServer.md) · [Variables](../topics/Variables.md) · [Event Scripts](../topics/Event_Scripts.md)

<sub>Source: [BI Community Wiki — publicVariable](https://community.bistudio.com/wiki/publicVariable) (revision 343848).</sub>
