Void: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "[[{{arma2}}]]" to "{{arma2}}")
m (Some wiki formatting)
Line 1: Line 1:
{{TOC|side}}
A variable of type '''Void''' is an '''undefined variable'''.
A variable of type '''Void''' is an '''undefined variable'''.


Line 5: Line 6:
You can use [[nil]] to undefine variables.
You can use [[nil]] to undefine variables.


myVar = 1;
<sqf>
...
myVar = 1;
myVar = nil;
// ...
myVar = nil;
myVar => undefined
// myVar is undefined
</sqf>


== Comparisons ==
== Comparisons ==
Line 17: Line 19:
'''Example:'''
'''Example:'''


// error
<sqf>
[[if]] (undefinedVar == ...) [[then]] ...
// error
if (undefinedVar == definedVar) then { /* ... */ };
</sqf>
<sqf>
// error
if (undefinedVar == undefinedVar) then { /* ... */ };
</sqf>


// error
[[if]] (undefinedVar == undefinedVar) [[then]] ...




 
In {{ofp}}, a Variable becomes '''undefined''' when it is assigned to an undefined value, or an expression which refers to an undefined value somewhere.
In Operation Flashpoint, a Variable becomes '''undefined''' when it is assigned to an undefined value, or an expression which refers to an undefined value somewhere.


== Names ==
== Names ==
Line 31: Line 36:
The [[String]] representation of an undefined variable is one of the following:
The [[String]] representation of an undefined variable is one of the following:


[[Anything]]: scalar bool array string 0xfcffffef (OFP)
[[Anything]]: [[scalar bool array string 0xfcffffef]] ({{Name|ofp|short}})


[[Anything]]: scalar bool array string 0xe0ffffef (ArmA)
[[Anything]]: [[scalar bool array string 0xe0ffffef]] ({{Name|arma1|short}})


[[Nothing]]: scalar bool array string nothing 0xfcffffef<br>
[[Nothing]]: scalar bool array string nothing 0xfcffffef


[[Number]]: scalar
[[Number]]: scalar
Line 48: Line 53:


'''Example''':
'''Example''':
<sqf>
defined=false;if var==var then {defined=true};if var!=var then {defined=true};
if !defined then {/*we know it is undefined here*/}
</sqf>


defined=false;if var==var then {defined=true};if var!=var then {defined=true};
The code above should not work in {{GameCategory|arma2|link=y}}, as stated [[ArmA: Editing#Forward Compatility|here]].
if !defined then {/*we know it is undefined here*/}


The code above should not work in [[:Category:Arma 2|{{arma2}}]], as stated [[ArmA:_Editing#Forward_Compatility|here]].
In {{Name|arma1|short}} or later [[isNil]] is the preferred way to check for this, like
 
<sqf>isNil "varName";</sqf>
In Armed Assault or later [[isNil]] is the preferred way to check for this, like
  '''isNil''' "varName"


== Type Inference ==
== Type Inference ==


Suppose the variable '''a''' is undefined, and we set the variable '''b''' like so:<br>
Suppose the variable '''a''' is undefined, and we set the variable '''b''' like so:<br>
b = a + []
<sqf>b = a + [];</sqf>


The inferred type of b is now array - since b was the product result of an array [[a plus b|add]] operation with a definite array ([]) and an unknown type (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.
'''b''''s string representation will now be 'array', and b wil be considered an undefined array.


[[Category: Magic Types]]
[[Category: Magic Types]]

Revision as of 16:23, 22 July 2022

A variable of type Void is an undefined variable.

Undefining Variables

You can use nil to undefine variables.

myVar = 1; // ... myVar = nil; // myVar is undefined

Comparisons

No comparison with variables of this type will work.

Example:

// error if (undefinedVar == definedVar) then { /* ... */ };
// error if (undefinedVar == undefinedVar) then { /* ... */ };


In Operation Flashpoint, a Variable becomes undefined when it is assigned to an undefined value, or an expression which refers to an undefined value somewhere.

Names

The String representation of an undefined variable is one of the following:

Anything: scalar bool array string 0xfcffffef (OFP)

Anything: scalar bool array string 0xe0ffffef (ArmA)

Nothing: scalar bool array string nothing 0xfcffffef

Number: scalar

Boolean: bool

Array: array

Caution: the string specification of the undefined variables is undocumented, and it is very likely to change in future version of the scripting language.

The reliable way to check if the variable is undefined is that it silently fails any expression evaluations on it.

Example:

defined=false;if var==var then {defined=true};if var!=var then {defined=true}; if !defined then {/*we know it is undefined here*/}

The code above should not work in Arma 2, as stated here.

In ArmA or later isNil is the preferred way to check for this, like

isNil "varName";

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.