A variable of type Void is an undefined variable.
Undefining Variables
nil can be used to undefine variables.
myVar = 1;
// ...
myVar = nil;
// myVar is undefined
String Representation
The String representation of an undefined variable depends on its inferred type:
| Data Type | String |
|---|---|
| Anything | scalar bool array string 0xfcffffef (OFP) scalar bool array string 0xe0ffffef (ArmA) |
| Nothing | scalar bool array string nothing 0xfcffffef |
| Number | scalar |
| Boolean | bool |
| Array | array |
Comparisons
No comparison with any variables will work.
Example:
// error
if (undefinedVar == definedVar) then { /* ... */ };
// error
if (undefinedVar == undefinedVar) then { /* ... */ };
Detect an Undefined Variable
The isNil command, introduced in Armed Assault, allows to detect if a variable exists or not:
HelloThere = 42;
isNil "HelloThere"; // false
HelloThere = nil;
isNil "HelloThere"; // true
isNil Workaround 1 (Operation Flashpoint v1.00)
_nil = format ["%1", _undefinedVariable]
? (format ["%1", variableToTest] == _nil) : hint "variableToTest is nil"
_nil = format ["%1", _undefinedVariable];
if (format ["%1", variableToTest] == _nil) then { hint "variableToTest is nil" };
isNil Workaround 2 (Operation Flashpoint v1.00)
Caution
This information is obsolete. Armed Assault introduced isNil, and Arma 2 forbade undefined variables usage in script - see ArmA: Editing#Forward Compatibility.
The alternative way to check if a variable is undefined before isNil existence is that it silently fails any expression evaluations on it:
defined = false;
if (var == var) then
{
defined = true;
};
if (var != var) then
{
defined = true;
};
if (!defined) then
{
// we know var is undefined here
};
Type Inference
Suppose the variable a is undefined, and we set the variable b like so:
b = a + [];
The inferred type of b is now array - since b was the product result of an array add operation with a definite array ([]) and an unknown type (a)
b's string representation will now be "array", and b wil be considered an undefined array.