Jump to content
thetrooper

Variable error (unit doesn't exist)

Recommended Posts

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

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

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

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

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
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×