isNil: Difference between revisions
Jump to navigation
Jump to search
m (Text replace - "{{uc:{{PAGENAME}}}}" to "{{uc:{{PAGENAME}}}} {{uc:{{PAGENAME}}}}") |
(formatting, added see also) |
||
Line 7: | Line 7: | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| Tests whether the variable defined by the [[String]] argument is undefined, or whether an expression result passed as [[Code]] is undefined. The | | Tests whether the variable defined by the [[String]] argument is undefined, or whether an expression result passed as [[Code]] is undefined. | ||
<br>The command returns [[true]] if the variable or the expression result is undefined (i.e. the expression result is [[Void]]), and [[false]] in all other cases. |= Description | |||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| | | '''isnil''' variable |= Syntax | ||
|p1= variable: [[String]] or [[Code]]|= Parameter 1 | |p1= variable: [[String]] or [[Code]]|= Parameter 1 | ||
Line 16: | Line 17: | ||
| [[Boolean]] |= Return value | | [[Boolean]] |= Return value | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
|x1 = <code> [[if]] ( | |||
| | |x1 = <code>[[if]] ([[isNil]] "_pokus") [[then]] { | ||
_pokus = 0; | |||
};</code>|= Example1 | |||
____________________________________________________________________________________________ | |||
| [[nil]], [[Variables]] |= See also | |||
}} | }} |
Revision as of 16:24, 21 April 2014
Description
- Description:
- Tests whether the variable defined by the String argument is undefined, or whether an expression result passed as Code is undefined.
The command returns true if the variable or the expression result is undefined (i.e. the expression result is Void), and false in all other cases. - Groups:
- Uncategorised
Syntax
Examples
Additional Information
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Notes
- ColonelSandersLite
I recently had a strange experience with this command. I forgot to wrap the name of the variable with quotes, and it returned the opposite of the true null status of the variable. Just something to watch out for.- General Barron
^ If you don't wrap the name of the variable in quotes, then it will instead read the value of the variable itself. If that variable is a string or code, then the command will use that string or code held by the variable. Example:_myvar = "_hisvar"; isnil _myvar; //will return true if _hisvar is null _myvar = {tank1}; sleep (random 50); isnil _myvar; //will return if tank1 is nil, at the time the isnil command is checked (not at the time _myvar is established)
--General Barron 10:37, 30 December 2009 (CET)
- Igneous01
isNil is also able to check if an expression is undefined. As such, an alternative way to check variables would be:isNil {variable}
you can use this method to also check if variables defined using setVariable exist as well:
isNil {player getVariable "Something"}
As well as testing if a function returns a value
func_ChangeVehicleName = { _this setVehicleVarName "newName"; }; if (isNil {player call func_ChangeVehicleName}) // returns true, because this function does not return anything