thetrooper 10 Posted February 20, 2016 Hi all, I've got an issue with if a unit doesn't exist and I have a script running Arma3 throws up an error. How can I avoid this?Example.I got enemy units with variables from en1 - en34 (34 being total number)en15 has a has a probability set of 75% he also has en15 setUnitPos "MIDDLE" set in the init.sqf. en15 doesn't exist and get an error. I'm sure I never had that before. Is there any way to avoid it? Share this post Link to post Share on other sites
austin_medic 109 Posted February 20, 2016 if(!isNull en15) then { //yourcodehere }; Share this post Link to post Share on other sites
thetrooper 10 Posted February 20, 2016 Would I have to write that for every unit or is there simplar way maybe in some sort of array? Share this post Link to post Share on other sites
thetrooper 10 Posted February 20, 2016 if(!isNull en1) then {en1 setCaptive true;}; if(!is> Error position: <en1) then {en1 setCaptive true;}; if(!is> Error Undefined variable in expression: en1 Still has an error unfortunately. My code below: if(!isNull en1) then {en1 setCaptive true;}; Share this post Link to post Share on other sites
austin_medic 109 Posted February 20, 2016 try this instead: if(!isNil "en15") then { //docode }; to speed things up and save yourself the headache of typing out the same thing 40 times you could use a forEach loop { if(!isNil (format["%1",_x])) then { //docode }; } forEach [array-of-unit names]; Share this post Link to post Share on other sites
thetrooper 10 Posted February 20, 2016 No good on the first code I'm afraid austin_medic. The second would be more ideal at the moment though I'm still going to need the first for loading out kit for the units eventually :S Share this post Link to post Share on other sites
thetrooper 10 Posted February 20, 2016 bump... still lost with this one Share this post Link to post Share on other sites
killzone_kid 1326 Posted February 21, 2016 if(!isNull en1) then {en1 setCaptive true;}; if(!is> Error position: <en1) then {en1 setCaptive true;}; if(!is> Error Undefined variable in expression: en1 Still has an error unfortunately. My code below: if(!isNull en1) then {en1 setCaptive true;}; if(!isNil "en1" && {en1 isEqualType objNull}) then {en1 setCaptive true;}; Share this post Link to post Share on other sites