publicVariable: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Fix description and clean comments)
m (Some wiki formatting)
 
(37 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| ofp |Game name=
|game1= ofp
|version1= 1.34


|1.34|Game version=
|game2= ofpe
|version2= 1.00


|arg= local |Arguments in MP=
|game3= arma1
|version3= 1.00


|eff= global |Effects in MP=
|game4= arma2
____________________________________________________________________________________________
|version4= 1.00


| Reliably broadcasts [[missionNamespace]] variable and its '''current''' value to all computers (server/client).<br>
|game5= arma2oa
Variables broadcast with [[publicVariable]] during a mission will be available to [[Join In Progress|JIP]] clients with the value they held at the time.<br>
|version5= 1.50
 
|game6= tkoh
|version6= 1.00
 
|game7= arma3
|version7= 0.50
 
|gr1= Multiplayer
 
|gr2= Variables
 
|arg= local
 
|eff= global
 
|descr= Reliably broadcasts [[missionNamespace]] variable and its '''current''' value to all computers (server/client).<br>
Variables broadcast with [[publicVariable]] during a mission will be available to [[Multiplayer Scripting#Join In Progress|JIP]] clients with the value they held at the time.<br>
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.
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.
{{Important | Using [[publicVariable]] too frequently and/or with a lot of data can cause other aspects of the game to experience bandwidth problems.}}
{{Feature|important|Using [[publicVariable]] too frequently and/or with a lot of data can cause other aspects of the game to experience bandwidth problems.}}
<br>
<br>
The following [[Data Types]] are supported:
The following [[:Category: Data Types| Data Types]] are supported:
{{{!}} class{{=}}"wikitable" style{{=}}"text-align: center"
{{{!}} class="wikitable align-center"
! Type
! Type
{{!}} [[Number]]
{{!}} [[Number]]
Line 24: Line 43:
{{!}} [[Group]]
{{!}} [[Group]]
{{!}} [[String]]
{{!}} [[String]]
{{!}} [[Text]]
{{!}} [[Structured Text|Text]]
{{!}} [[Array]]
{{!}} [[Array]]
{{!}} [[Code]]
{{!}} [[Code]]
{{!}} [[Nothing]] ([[nil]])
{{!}} [[Nothing]] ([[nil]])
{{!}} [[HashMap]]
{{!}}-
{{!}}-
! Since
! Since
{{!}}
{{!}} colspan="4" {{!}} {{GVI|ofp|1.34}}
{{!}} {{GVI|ofp|1.34}}
{{!}} colspan="2" {{!}} {{GVI|arma1|1.00}}
{{!}} {{GVI|ofp|1.34}}
{{!}} colspan="2" {{!}} {{GVI|arma1|1.09}}
{{!}} {{GVI|ofp|1.34}}
{{!}} {{GVI|arma|1.00}}
{{!}} {{GVI|arma|1.00}}
{{!}} {{GVI|arma|1.09}}
{{!}} {{GVI|arma|1.09}}
{{!}} {{GVI|arma3|1.26}}
{{!}} {{GVI|arma3|1.26}}
{{!}} {{GVI|arma3|2.02}}
{{!}}}
{{!}}}


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


| [[publicVariable]] varName |Syntax=
|s1= [[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=
|r1= [[Nothing]]
____________________________________________________________________________________________


|x1= <code>TAG_MyPublicVariable = 0;
|x1= <sqf>
TAG_MyPublicVariable = 0;
TAG_MyPublicVariable = 1;
TAG_MyPublicVariable = 1;
[[publicVariable]] "TAG_MyPublicVariable"; {{cc|other clients will receive the "TAG_MyPublicVariable" variable with a '''1''' value}}
publicVariable "TAG_MyPublicVariable"; // 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; // needs to be broadcast again - synchronisation is not automatic
</sqf>


|x2= JIP example:
|x2= JIP example:
<code>[[if]] ([[isNil]] "TAG_CurrentTarget") [[then]] {{cc|has the variable already been set and broadcast?}}
<sqf>
if (isNil "TAG_CurrentTarget") then // has the variable already been set and broadcast?
{
{
TAG_CurrentTarget = [[objNull]]; {{cc|if not, set it on the local machine}}
TAG_CurrentTarget = objNull; // if not, set it on the local machine
};
};


[[player]] [[doTarget]] TAG_CurrentTarget;</code> |Example 2=
player doTarget TAG_CurrentTarget;
____________________________________________________________________________________________
</sqf>
 
| [[Multiplayer Scripting]], [[Initialization Order]], [[addPublicVariableEventHandler]], [[publicVariableClient]], [[publicVariableServer]], [[Variables#Global Scope|Global Variable]], [[Event Scripts]], [[Join In Progress]] |See also=
}}


<h3 style="display:none">Notes</h3>
|x3= <sqf>
<dl class="command_description">
TAG_BossName = "EvilBigBoss";
<!-- Note Section BEGIN -->


<dd class="notedate">Posted on 12 April, 2008
publicVariable TAG_BossName; // wrong - will try to publicVariable "EvilBigBoss" variable, that does not exist
<dt class="note">[[User:Icemotoboy|Icemotoboy]]
publicVariable "TAG_BossName"; // correct - important, do not forget the QUOTES
<dd class="note">Be sure to place your variable name in quotation marks.
</sqf>
This may sound awfully simple, but many times I have forgotten to do this, and it has resulted in no end of headaches for me.


<!-- Note Section END -->
|seealso= [[Multiplayer Scripting]] [[Initialisation Order]] [[addPublicVariableEventHandler]] [[publicVariableClient]] [[publicVariableServer]] [[Variables#Global Scope|Global Variable]] [[Event Scripts]] [[Multiplayer Scripting#Join In Progress|Join In Progress]]
</dl>
}}
 
<h3 style="display:none">Bottom Section</h3>
[[Category:Scripting Commands OFP 1.46|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.96|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Take On Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Command Group: Multiplayer|{{uc:{{PAGENAME}}}}]]

Latest revision as of 15:57, 26 July 2023

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) HashMap
Since Logo A0.png1.34 Logo A1 black.png1.00 Logo A1 black.png1.09 Arma 3 logo black.png1.26 Arma 3 logo black.png2.02
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 - important, do not forget the QUOTES

Additional Information

See also:
Multiplayer Scripting Initialisation Order addPublicVariableEventHandler publicVariableClient publicVariableServer Global Variable Event Scripts Join 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