Namespace: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Finished overhaul)
m (Some wiki formatting)
 
(5 intermediate revisions by 3 users not shown)
Line 2: Line 2:
{{GVI|arma2|1.00}}
{{GVI|arma2|1.00}}


 
A [[Namespace]] is a container for [[Variables]].
A [[Namespace]] is a container for [[Variables]]. Any [[Variables#Scopes|global]] variable is always part of exactly one namespace - another namespace may contain a variable with the same [[Identifier]], but they remain two distinct independent variables. Scripts and functions are always executed in the context of some namespace.
Any [[Variables#Scopes|global]] variable is always part of exactly one namespace - another namespace may contain a variable with the same [[Identifier]], but they remain two distinct independent variables.
Scripts and functions are always executed in the context of some namespace.


The default namespace is the [[missionNamespace]].
The default namespace is the [[missionNamespace]].
Line 9: Line 10:


== Namespaces ==
== Namespaces ==
{| class="wikitable"
{| class="wikitable"
! Game !! Namespace !! Description !! Lifetime
! Game
! Namespace
! Description
! Lifetime
|-
|-
| {{GVI|arma2|1.00}}
| {{GVI|arma2|1.00}}
Line 34: Line 39:
| {{GVI|arma3|2.00}}
| {{GVI|arma3|2.00}}
| [[localNamespace]]
| [[localNamespace]]
| This namespace is like the [[missionNamespace]], except that its variables can not be broadcast (e.g. with [[publicVariable]]) or serialized.
| This namespace is like the [[missionNamespace]], except that its variables can not be sent over network (e.g. with [[publicVariable]]) or serialised.
| style="background-color: lightgreen" | Mission duration
| style="background-color: lightgreen" | Mission duration
|-
|-
Line 41: Line 46:
| The namespace used by [[ArmA: Armed Assault: Server Side Scripting|Server Event Handlers]]. This namespace is only available on servers.
| The namespace used by [[ArmA: Armed Assault: Server Side Scripting|Server Event Handlers]]. This namespace is only available on servers.
| style="background-color: lightyellow" | Game session
| style="background-color: lightyellow" | Game session
|-
| {{GVI|arma3|2.10}}
| [[missionProfileNamespace]]
| This namespace is like [[profileNamespace]] but is also attached to a [[missionName]] or [[Description.ext#missionGroup|missionGroup]]. Automatically loaded before [[Event Scripts#init.sqf|init.sqf]].
| style="background-color: lightskyblue" | [[Profile]] lifetime
|}
|}




== Namespace Serialization ==
== Serialisation ==
Only the [[missionNamespace]] is serialized, i.e. only the variables from this namespace are saved when the game is saved (e.g. with [[saveGame]]) and loaded when the game is loaded (e.g. with [[loadGame]]). This is also the reason the game will complain that one should use [[disableSerialization]] when storing UI variables in [[missionNamespace]] - UI elements are temporary and therefore exempt from serialization by default.
 
Only the [[missionNamespace]] is serialised, as in only the variables from this namespace are saved when the game is saved (e.g. with [[saveGame]]) and loaded when the game is loaded (e.g. with [[loadGame]]).
This is also the reason the game will complain that one should use [[disableSerialization]] when storing UI variables in [[missionNamespace]] - UI elements are temporary and therefore exempt from serialisation by default.
 


== Scripting ==


== Scripting with Namespaces ==
Interacting with namespaces is not difficult:
Interacting with namespaces is not difficult:
* The [[getVariable]] and [[setVariable]] commands can be used to work with variables from different namespaces.
* The [[getVariable]] and [[setVariable]] commands can be used to work with variables from different namespaces.
* The [[with]]-do-construct can be used to switch the context of an entire code block to another namespace.
* The [[with]]-[[do]] construct can be used to switch the context of an entire code block to another namespace.
* The [[currentNamespace]] command can be used to obtain the namespace which the calling script is running in.
* The [[currentNamespace]] command can be used to obtain the namespace which the calling script is running in.



Latest revision as of 14:59, 26 August 2024

Logo A2.png1.00

A Namespace is a container for Variables. Any global variable is always part of exactly one namespace - another namespace may contain a variable with the same Identifier, but they remain two distinct independent variables. Scripts and functions are always executed in the context of some namespace.

The default namespace is the missionNamespace.


Namespaces

Game Namespace Description Lifetime
Logo A2.png1.00 missionNamespace The global namespace of the mission. Every mission has its own missionNamespace. Mission duration
Logo A2.png1.00 parsingNamespace The global namespace attached to the Config Parser. Game session
Logo A2.png1.00 uiNamespace The global namespace attached to the user interface. Game session
tkoh logo small.png1.00 profileNamespace The global namespace attached to the user profile. Profile lifetime
Arma 3 logo black.png2.00 localNamespace This namespace is like the missionNamespace, except that its variables can not be sent over network (e.g. with publicVariable) or serialised. Mission duration
Arma 3 logo black.png2.06 serverNamespace The namespace used by Server Event Handlers. This namespace is only available on servers. Game session
Arma 3 logo black.png2.10 missionProfileNamespace This namespace is like profileNamespace but is also attached to a missionName or missionGroup. Automatically loaded before init.sqf. Profile lifetime


Serialisation

Only the missionNamespace is serialised, as in only the variables from this namespace are saved when the game is saved (e.g. with saveGame) and loaded when the game is loaded (e.g. with loadGame). This is also the reason the game will complain that one should use disableSerialization when storing UI variables in missionNamespace - UI elements are temporary and therefore exempt from serialisation by default.


Scripting

Interacting with namespaces is not difficult:

  • The getVariable and setVariable commands can be used to work with variables from different namespaces.
  • The with-do construct can be used to switch the context of an entire code block to another namespace.
  • The currentNamespace command can be used to obtain the namespace which the calling script is running in.