{"name":"isNil","operator":null,"title":"isNil","type":"command","url":"https://community.bistudio.com/wiki/isNil","revid":370850,"updated":"2025-02-18T00:01:09Z","groups":["Variables"],"status":"ok","replaced_by":[],"games":[{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma1","name":"Armed Assault","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"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","since":null,"effect":null,"exec":null,"params":[{"name":"variableName","type":"String","optional":false,"default":null,"description":"missionNamespace's or local variable's identifier (e.g \"globalVariable\", \"_localVariable\")","types":["String"],"since":null,"text":"variableName: **String** - missionNamespace's or local variable's identifier (e.g \"globalVariable\", \"_localVariable\")"}],"returns":{"type":"Boolean","types":["Boolean"],"description":"true if variable is nil or undefined","text":"Boolean - true if variable is nil or undefined"},"form":"unary","operator":null,"left":null,"right":{"text":"variableName","types":["String"]}},{"syntax":"isNil code","since":null,"effect":null,"exec":null,"params":[{"name":"code","type":"Code","optional":false,"default":null,"description":"code to evaluate:\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).","types":["Code"],"since":null,"text":"code: Code - code to evaluate:\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)."}],"returns":{"type":"Boolean","types":["Boolean"],"description":"true if code returns Nothing, false otherwise","text":"Boolean - true if *code* returns Nothing, false otherwise"},"form":"unary","operator":null,"left":null,"right":{"text":"code","types":["Code"]}},{"syntax":"namespace isNil variableName","since":"arma3 2.18","effect":null,"exec":null,"params":[{"name":"namespace","type":"Namespace, Object, Group, HashMap, Arma 3 v2.20 Control and Display","optional":false,"default":null,"description":null,"types":["Namespace","Object","Group","HashMap","Control","Display"],"since":null,"text":"namespace: Namespace, Object, Group, HashMap, Arma 3 v2.20 Control and Display"},{"name":"variableName","type":"String","optional":false,"default":null,"description":null,"types":["String"],"since":null,"text":"variableName: String"}],"returns":{"type":"Boolean","types":["Boolean"],"description":"true if variable is nil or undefined","text":"Boolean - true if variable is nil or undefined"},"form":"binary","operator":null,"left":{"text":"namespace","types":["Namespace","Object","Group","HashMap","Control","Display"]},"right":{"text":"variableName","types":["String"]}}],"examples":[{"text":"```sqf\nif (isNil \"TAG_globalVariable\") then { TAG_globalVariable = 0 };\nif (isNil \"_localVariable\") then { hint \"_localVariable is nil\" };\n```","code":["if (isNil \"TAG_globalVariable\") then { TAG_globalVariable = 0 };\nif (isNil \"_localVariable\") then { hint \"_localVariable is nil\" };"]},{"text":"```sqf\nisNil { player getVariable \"someVar\" };\n```","code":["isNil { player getVariable \"someVar\" };"]},{"text":"```sqf\n_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\n```","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\n\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\" };"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["nil","Variables","Scheduler"],"notes":[],"categories":["ArmA: Armed Assault: New Scripting Commands","ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Variables","Introduced with Armed Assault version 1.00","Scripting Commands","Take On Helicopters: Scripting Commands"]}