alleycat 28 Posted March 18, 2016 I want to check for a variable of an object that was set by setvariable. How would I check if the variable exists at all to prevent an error? Share this post Link to post Share on other sites
alleycat 28 Posted March 18, 2016 EDIT I think https://community.bistudio.com/wiki/isNilis going to work. 1 Share this post Link to post Share on other sites
Moerderhoschi 107 Posted March 18, 2016 _var = missionNameSpace getVariable ["myVar",-1]; if (_var != -1) then {do stuff} else {not defined, so do other stuff} Share this post Link to post Share on other sites
NeoArmageddon 958 Posted March 18, 2016 You can also use the syntax of getvariable to set a default value. That will also prevent errors when used correct: private _var = _someObj getvariable["variable_of_doom",objNull]; if(!isNull _var) then { //Do something with var } else { diag_log "Error: Variable_of_doom was not set."; }; Edit: Moerderhoschi was faster.... D'Oh! Share this post Link to post Share on other sites
barbolani 198 Posted March 19, 2016 Those two methods are ok, but what if a possible value is -1 or null object? They are used to avoid some errors, not to really check if a variable is nil. The first one is the best. Share this post Link to post Share on other sites
sarogahtyp 1108 Posted March 19, 2016 That thing ckecks Nil: if (isNil {_your_object getVariable "objects_variable"}) then { hint "it is Nil"; }else{ hint "it is something"; }; Share this post Link to post Share on other sites