{"name":"isNil","title":"isNil","type":"command","url":"https://community.bistudio.com/wiki/isNil","revid":370850,"updated":"2025-02-18T00:01:09Z","groups":["Variables"],"status":"ok","games":{"arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma1 1.00","arma3_since":"0.50","description":"Tests whether a variable is nil or undefined from its identifier, or whether the given expression evaluates to nil or Nothing.\n\n> [!NOTE]\n> This command does not exist in Operation Flashpoint/Arma: Cold War Assault but can be emulated (see Example 5).","syntaxes":[{"syntax":"isNil variableName","params":[{"name":"variableName","type":"String","description":"missionNamespace's or local variable's identifier (e.g \"globalVariable\", \"_localVariable\")","type_expr":"String","text":"variableName: **String** - missionNamespace's or local variable's identifier (e.g \"globalVariable\", \"_localVariable\")"}],"returns":{"type":"Boolean","type_expr":"Boolean","description":"true if variable is nil or undefined"},"form":"unary","right":{"text":"variableName"}},{"syntax":"isNil code","params":[{"name":"code","type":"Code","description":"code to evaluate:\n\n- the code **will** be executed; `isNil { player setDamage 1 };` *will* kill the player\n- the code will not be allowed to suspend while expression is evaluated, even if the parent scope allows it (see Example 4).","type_expr":"Code"}],"returns":{"type":"Boolean","type_expr":"Boolean","description":"true if code returns Nothing, false otherwise","text":"Boolean - true if *code* returns Nothing, false otherwise"},"form":"unary","right":{"text":"code"}},{"syntax":"namespace isNil variableName","since":"arma3 2.18","params":[{"name":"namespace","type":"Namespace, Object, Group, HashMap, Arma 3 v2.20 Control and Display","type_expr":"Namespace | Object | Group | HashMap | Control | Display"},{"name":"variableName","type":"String","type_expr":"String"}],"returns":{"type":"Boolean","type_expr":"Boolean","description":"true if variable is nil or undefined"},"form":"binary","left":{"text":"namespace"},"right":{"text":"variableName"}}],"examples":[{"code":["if (isNil \"TAG_globalVariable\") then { TAG_globalVariable = 0 };\nif (isNil \"_localVariable\") then { hint \"_localVariable is nil\" };"]},{"code":["isNil { player getVariable \"someVar\" };"]},{"code":["_myArray = [0, 1];\nisNil { _myArray select 0 }; // returns false\nisNil { _myArray select 1 }; // returns false\nisNil { _myArray select 2 }; // returns true\nisNil { _myArray select 3 }; // throws a script error. only length+1 select is allowed"]},{"text":"This trick forces executing something in Unscheduled Environment:\n\n```sqf\n0 spawn {\n    systemChat str canSuspend;        // chat shows true\n    isNil { hint str canSuspend };    // hint shows false\n};\n```","code":["0 spawn {\n\tsystemChat str canSuspend;\t\t// chat shows true\n\tisNil { hint str canSuspend };\t// hint shows false\n};"]},{"text":"Operation Flashpoint String comparison workaround\nSQS Syntax:\n\n```sqs\n_nil = format [\"%1\", _undefinedVariable]\n? (format [\"%1\", variableToTest] == _nil) : hint \"variableToTest is nil\"\n```\n\nSQF Syntax:\n\n```sqf\n_nil = format [\"%1\", _undefinedVariable];\nif (format [\"%1\", variableToTest] == _nil) then { hint \"variableToTest is nil\" };\n```","code":["_nil = format [\"%1\", _undefinedVariable]\n? (format [\"%1\", variableToTest] == _nil) : hint \"variableToTest is nil\"","_nil = format [\"%1\", _undefinedVariable];\nif (format [\"%1\", variableToTest] == _nil) then { hint \"variableToTest is nil\" };"]}],"see_also":["nil","Variables","Scheduler"]}