---
name: "isNil"
type: command
status: ok
groups: ["Variables"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/isNil
revid: 370850
updated: 2025-02-18T00:01:09Z
---

# isNil

*Command · Variables · Arma 3 v0.50 · introduced in Armed Assault v1.00*

## Description

Tests whether a variable is [nil](../commands/nil.md) or undefined from its [identifier](../topics/Identifier.md), or whether the given expression evaluates to [nil](../commands/nil.md) or [Nothing](../topics/Nothing.md).

> [!NOTE]
> This command does not exist in Operation Flashpoint/Arma: Cold War Assault but can be emulated (see [#Example 5](../commands/isNil.md#example-5)).

## Syntax

### Syntax 1

```sqf
isNil variableName
```

**Parameters:**

- `variableName`: **[String](../topics/String.md)** - [missionNamespace](../commands/missionNamespace.md)'s or local [variable](../topics/Variables.md)'s [identifier](../topics/Identifier.md) (e.g "globalVariable", "_localVariable")

**Returns:** [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if variable is [nil](../commands/nil.md) or undefined

### Syntax 2

```sqf
isNil code
```

**Parameters:**

- `code`: [Code](../topics/Code.md) - code to evaluate:
  - the code **will** be executed; `isNil { player setDamage 1 };` *will* kill the player
  - the code will not be allowed to [suspend](../commands/canSuspend.md) while expression is evaluated, even if the parent scope allows it (see [#Example 4](../commands/isNil.md#example-4)).

**Returns:** [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if *code* returns [Nothing](../topics/Nothing.md), [false](../commands/false.md) otherwise

### Syntax 3

*since arma3 2.18*

```sqf
namespace isNil variableName
```

**Parameters:**

- `namespace`: [Namespace](../topics/Namespace.md), [Object](../topics/Object.md), [Group](../topics/Group.md), [HashMap](../topics/HashMap.md), Arma 3 v2.20 [Control](../topics/Control.md) and [Display](../topics/Display.md)
- `variableName`: [String](../topics/String.md)

**Returns:** [Boolean](../topics/Boolean.md) - [true](../commands/true.md) if variable is [nil](../commands/nil.md) or undefined

## Examples

### Example 1

```sqf
if (isNil "TAG_globalVariable") then { TAG_globalVariable = 0 };
if (isNil "_localVariable") then { hint "_localVariable is nil" };
```

### Example 2

```sqf
isNil { player getVariable "someVar" };
```

### Example 3

```sqf
_myArray = [0, 1];
isNil { _myArray select 0 }; // returns false
isNil { _myArray select 1 }; // returns false
isNil { _myArray select 2 }; // returns true
isNil { _myArray select 3 }; // throws a script error. only length+1 select is allowed
```

### Example 4

This trick forces executing something in [Unscheduled Environment](../topics/Scheduler.md):

```sqf
0 spawn {
    systemChat str canSuspend;        // chat shows true
    isNil { hint str canSuspend };    // hint shows false
};
```

### Example 5

Operation Flashpoint [String](../topics/String.md) comparison workaround

SQS Syntax:

```sqs
_nil = format ["%1", _undefinedVariable]
? (format ["%1", variableToTest] == _nil) : hint "variableToTest is nil"
```

[SQF Syntax](../topics/SQF_Syntax.md):

```sqf
_nil = format ["%1", _undefinedVariable];
if (format ["%1", variableToTest] == _nil) then { hint "variableToTest is nil" };
```

## See also

[nil](../commands/nil.md) · [Variables](../topics/Variables.md) · [Scheduler](../topics/Scheduler.md)

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