Namespace: Difference between revisions
m (Text replacement - "v1\.[9-9]{2}\.[0-9]{6}" to "v2.00") |
(Added serverNamespace, overhauled a little bit) |
||
Line 1: | Line 1: | ||
{{TOC|side}} | {{TOC|side}} | ||
{{ | {{GVI|arma2|1.00}} | ||
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. The default namespace is the [[missionNamespace]]. | |||
== Namespaces == | |||
The following commands return the [[Namespace]] type: | |||
{| class="wikitable" | {| class="wikitable" | ||
! Game !! Command !! Description | ! Game !! Command !! Description | ||
Line 19: | Line 21: | ||
| {{GVI|tkoh|1.00}} || [[profileNamespace]] || returns the global namespace attached to the user profile | | {{GVI|tkoh|1.00}} || [[profileNamespace]] || returns the global namespace attached to the user profile | ||
|- | |- | ||
| {{GVI|arma3|1.48}} || [[currentNamespace]] || returns the | | {{GVI|arma3|1.48}} || [[currentNamespace]] || returns the namespace which the calling script is running in | ||
|- | |- | ||
| {{GVI|arma3|2.00}} || [[localNamespace]] || returns the local namespace. | | {{GVI|arma3|2.00}} || [[localNamespace]] || returns the local namespace | ||
|- | |||
| {{GVI|arma3|2.06}} || [[serverNamespace]] || returns the server namespace | |||
|} | |} | ||
== Get namespace data == <!-- Remove? --> | |||
== Get namespace data == | |||
You can use the above with [[getVariable]] to get data. | You can use the above with [[getVariable]] to get data. | ||
== Set namespace data == | == Set namespace data == <!-- Remove? --> | ||
To set data to a namespace, there're two methods to do: | To set data to a namespace, there're two methods to do: | ||
Line 41: | Line 43: | ||
};</code> | };</code> | ||
[[missionNamespace]] is the default global namespace, so just | [[missionNamespace]] is the default global namespace, so just {{ic|VariableName {{=}} ''value'';}} will store data to [[missionNamespace]]. | ||
== Namespace Lifetimes == | == Namespace Lifetimes == <!-- TODO: Transform to a table --> | ||
=== missionNamespace === | === missionNamespace === | ||
The missionNamespace is the main default partition that exists for the duration of a mission. All variables defined in the missionNamespace will cease to exist when the mission ends. To make variables last longer than a mission, use different namespaces. | |||
=== uiNamespace and parsingNamespace === | === uiNamespace and parsingNamespace === | ||
These are | These are two different namespaces which have similar scope. Variables defined in these namespaces exist for the duration of the game executable running and are lost when the game is shut down. | ||
=== profileNamespace === | === profileNamespace === | ||
This namespace | This namespace holds variables for a very long time and is attached to the user profile. Different profiles will have own set of variables stored with them. The saving of the profileNamespace can be forced with the [[saveProfileNamespace]] command, but in {{arma3}} this command is executed by vanilla game scripts already, so saving is done automatically. | ||
=== localNamespace === | === localNamespace === | ||
Same lifetime as [[missionNamespace]] but variables cannot be broadcast or serialized. | |||
== Namespace | == Namespace Serialization == | ||
Only [[missionNamespace]] is serialized. This means that all variables in this namespace will be saved when the game is saved and loaded when the game is loaded. 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 | Only the [[missionNamespace]] is serialized. This means that all variables in this namespace will be saved when the game is saved and loaded when the game is loaded. 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. | ||
[[Category: Data Types]] | [[Category: Data Types]] | ||
[[Category: Introduced with Arma 2 version 1.00]] | [[Category: Introduced with Arma 2 version 1.00]] |
Revision as of 12:23, 25 February 2022
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
The following commands return the Namespace type:
Game | Command | Description |
---|---|---|
1.00 | missionNamespace | returns the global namespace attached to the mission |
1.00 | parsingNamespace | returns the global namespace attached to the Config Parser |
1.00 | uiNamespace | returns the global namespace attached to the user interface |
1.00 | profileNamespace | returns the global namespace attached to the user profile |
1.48 | currentNamespace | returns the namespace which the calling script is running in |
2.00 | localNamespace | returns the local namespace |
2.06 | serverNamespace | returns the server namespace |
Get namespace data
You can use the above with getVariable to get data.
Set namespace data
To set data to a namespace, there're two methods to do:
namespace setVariable ["variableName", value];
with namespace do {
variableName = value;
};
missionNamespace is the default global namespace, so just VariableName = value;
will store data to missionNamespace.
Namespace Lifetimes
missionNamespace
The missionNamespace is the main default partition that exists for the duration of a mission. All variables defined in the missionNamespace will cease to exist when the mission ends. To make variables last longer than a mission, use different namespaces.
uiNamespace and parsingNamespace
These are two different namespaces which have similar scope. Variables defined in these namespaces exist for the duration of the game executable running and are lost when the game is shut down.
profileNamespace
This namespace holds variables for a very long time and is attached to the user profile. Different profiles will have own set of variables stored with them. The saving of the profileNamespace can be forced with the saveProfileNamespace command, but in Arma 3 this command is executed by vanilla game scripts already, so saving is done automatically.
localNamespace
Same lifetime as missionNamespace but variables cannot be broadcast or serialized.
Namespace Serialization
Only the missionNamespace is serialized. This means that all variables in this namespace will be saved when the game is saved and loaded when the game is loaded. 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.