---
name: "with"
type: command
status: ok
groups: ["Program Flow", "Namespaces"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/with
revid: 369023
updated: 2024-08-26T13:58:14Z
---

# with

*Command · Program Flow, Namespaces · Arma 3 v0.50 · introduced in Arma 2 v1.00*

## Description

Creates a [With Type](../topics/With_Type.md) that is used inside a [do](../commands/do.md) construct in order to execute code inside a given namespace.

> [!IMPORTANT]
> To avoid the below-mentioned issue error (whether in [scheduled](../topics/Scheduler.md#scheduled-environment) or [unscheduled](../topics/Scheduler.md#unscheduled-environment) environment) use [setVariable](../commands/setVariable.md)/[getVariable](../commands/getVariable.md) with the desired [Namespace](../topics/Namespace.md).

## Syntax

```sqf
with namespace
```

**Parameters:**

- `namespace`: [Namespace](../topics/Namespace.md)

**Returns:** [With Type](../topics/With_Type.md)

## Examples

### Example 1

```sqf
_myWithType = with uiNamespace;
```

### Example 2

```sqf
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](../commands/for.md), [if](../commands/if.md), [try](../commands/try.md), [call](../commands/call.md)) started in a [scheduled](../topics/Scheduler.md#scheduled-environment) environment after small suspension if [with](../commands/with.md) was not the main scope; however, the issue does not arise if [with](../commands/with.md) is used in the parent scope:

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

## See also

[missionNamespace](../commands/missionNamespace.md) · [uiNamespace](../commands/uiNamespace.md) · [parsingNamespace](../commands/parsingNamespace.md) · [currentNamespace](../commands/currentNamespace.md)

## Community notes

**Hypoxic125** — 2023-02-23

**Using with:**

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

**is the same as:**

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

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

<sub>Source: [BI Community Wiki — with](https://community.bistudio.com/wiki/with) (revision 369023).</sub>
