publicVariable: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - " <h3 style="display:none">Notes</h3> <dl class="command_description"> <!-- Note Section BEGIN --> <!-- Note Section END --> </dl> " to "")
m (Text replacement - " *\| *([Cc]omments|COMMENTS|Game|[Gg]ame [Nn]ame|Game [Vv]ersion|Game Version \(number surrounded by NO SPACES\)|Multiplayer Arguments( \("local" or "global"\))?|Effects|Multiplayer Effects( \("local" or "global"\))?|Multiplayer Exe...)
Line 1: Line 1:
{{Command|Comments=
{{Command


| ofp |Game name=
| ofp


|1.34|Game version=
|1.34


|gr1 = Multiplayer |GROUP1=
|gr1 = Multiplayer


|gr2 = Variables |GROUP2=
|gr2 = Variables


|arg= local |Arguments in MP=
|arg= local |Arguments in MP=
Line 44: Line 44:


{{Important| It is not possible (and illogical) to transfer a local entity reference, such as [[Script|scripts]], [[Display|displays]] or [[createVehicleLocal|local objects]].<br>
{{Important| It is not possible (and illogical) to transfer a local entity reference, such as [[Script|scripts]], [[Display|displays]] or [[createVehicleLocal|local objects]].<br>
Also, note that [[Team Member]] is not supported.}} |Description=
Also, note that [[Team Member]] is not supported.}}


| [[publicVariable]] varName |Syntax=
| [[publicVariable]] varName


|p1= varName: [[String]] - the [[Variables#Global Scope|global variable]]'s [[Identifier]] |Parameter 1=
|p1= varName: [[String]] - the [[Variables#Global Scope|global variable]]'s [[Identifier]]


| [[Nothing]] |Return value=
| [[Nothing]]


|x1= <code>TAG_MyPublicVariable = 0;
|x1= <code>TAG_MyPublicVariable = 0;
Line 56: Line 56:
[[publicVariable]] "TAG_MyPublicVariable"; {{cc|other clients will receive the "TAG_MyPublicVariable" variable with a '''1''' value}}
[[publicVariable]] "TAG_MyPublicVariable"; {{cc|other clients will receive the "TAG_MyPublicVariable" variable with a '''1''' value}}


TAG_MyPublicVariable = 2; {{cc|needs to be broadcast again - synchronisation is not automatic}}</code> |Example 1=
TAG_MyPublicVariable = 2; {{cc|needs to be broadcast again - synchronisation is not automatic}}</code>


|x2= JIP example:
|x2= JIP example:
Line 64: Line 64:
};
};


[[player]] [[doTarget]] TAG_CurrentTarget;</code> |Example 2=
[[player]] [[doTarget]] TAG_CurrentTarget;</code>


|x3= <code>TAG_BossName = "EvilBigBoss";
|x3= <code>TAG_BossName = "EvilBigBoss";


[[publicVariable]] TAG_BossName; {{cc|wrong - will try to publicVariable "EvilBigBoss" variable, that does not exist}}
[[publicVariable]] TAG_BossName; {{cc|wrong - will try to publicVariable "EvilBigBoss" variable, that does not exist}}
[[publicVariable]] {{Color|red|"}}TAG_BossName{{Color|red|"}}; {{cc|correct - do not forget the {{Color|red|quotes}}}}</code> |Example 3=
[[publicVariable]] {{Color|red|"}}TAG_BossName{{Color|red|"}}; {{cc|correct - do not forget the {{Color|red|quotes}}}}</code>


| [[Multiplayer Scripting]], [[Initialization Order]], [[addPublicVariableEventHandler]], [[publicVariableClient]], [[publicVariableServer]], [[Variables#Global Scope|Global Variable]], [[Event Scripts]], [[Multiplayer Scripting#Join In Progress|Join In Progress]] |See also=
| [[Multiplayer Scripting]], [[Initialization Order]], [[addPublicVariableEventHandler]], [[publicVariableClient]], [[publicVariableServer]], [[Variables#Global Scope|Global Variable]], [[Event Scripts]], [[Multiplayer Scripting#Join In Progress|Join In Progress]]
}}
}}



Revision as of 02:22, 18 January 2021

Hover & click on the images for description

Description

Description:
Reliably broadcasts missionNamespace variable and its current value to all computers (server/client).
Variables broadcast with publicVariable during a mission will be available to JIP 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 (such as init.sqf) is run.
Using publicVariable 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 Boolean Object Group String Text Array Code Nothing (nil)
Since Logo A0.png1.34 Logo A0.png1.34 Logo A0.png1.34 Logo A1 black.png1.00 Logo A1 black.png1.00 Logo A1 black.png1.09 Logo A1 black.png1.09 Arma 3 logo black.png1.26
It is not possible (and illogical) to transfer a local entity reference, such as scripts, displays or local objects.
Also, note that Team Member is not supported.
Groups:
MultiplayerVariables

Syntax

Syntax:
publicVariable varName
Parameters:
varName: String - the global variable's Identifier
Return Value:
Nothing

Examples

Example 1:
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: 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:
TAG_BossName = "EvilBigBoss"; publicVariable TAG_BossName; // wrong - will try to publicVariable "EvilBigBoss" variable, that does not exist publicVariable "TAG_BossName"; // correct - do not forget the quotes

Additional Information

See also:
Multiplayer ScriptingInitialization OrderaddPublicVariableEventHandlerpublicVariableClientpublicVariableServerGlobal VariableEvent ScriptsJoin In Progress

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note

Bottom Section