Arma 3 Scripting

with

  • Arma 3 v0.50
  • First in Arma 2 v1.00

Command · also in Namespaces · Markdown · JSON · original wiki page

Description

Creates a With Type that is used inside a do construct in order to execute code inside a given namespace.

Important

To avoid the below-mentioned issue error (whether in scheduled or unscheduled environment) use setVariable/getVariable with the desired Namespace.

Syntax

with namespace

Parameters:

Returns: With Type

Examples

Example 1

_myWithType = with uiNamespace;

Example 2

with missionNamespace do { global = global + 1 };

Problems

When used in a do-construct in scripts with allowed suspension, a namespace switching might unexpectedly occur inside some scopes (for, if, try, call) started in a scheduled environment after small suspension if with was not the main scope; however, the issue does not arise if with is used in the parent scope:

namespace switch risk namespace switch safe
0 spawn
{
    with uiNamespace do
    {
        for "_i" from 1 to 1 do
        {
            systemChat str [
                currentNamespace isEqualTo uiNamespace,
                currentNamespace isEqualTo missionNamespace
            ];
            // result [true, false]
            sleep 0.05; // <-- small suspension
            systemChat str [
                currentNamespace isEqualTo uiNamespace,
                currentNamespace isEqualTo missionNamespace
            ];
            // result [false, true] <-- switching
        };
    };
};
with uiNamespace do
{
    0 spawn
    {
        for "_i" from 1 to 1 do
        {
            systemChat str [
                currentNamespace isEqualTo uiNamespace,
                currentNamespace isEqualTo missionNamespace
            ];
            // result [true, false]
            sleep 0.05; // <-- small suspension
            systemChat str [
                currentNamespace isEqualTo uiNamespace,
                currentNamespace isEqualTo missionNamespace
            ];
            // result [true, false] <-- NO switching
        };
    };
};

See also

missionNamespace · uiNamespace · parsingNamespace · currentNamespace

Community notes

Hypoxic125

Using with:

with profileNamespace do {
    myVariable = "Hello!";
};

is the same as:

profileNamespace setVariable ["myVariable", "Hello!"];

This allows you to quickly modify/use variables within a namespace without using get/setvariable every time.