Jump to content
Sign in to follow this  
OLO

'getVariable' and units array

Recommended Posts

Hello

I have an array that consist of several units like:

units_array = [unit1,unit2,unit3,unit4,unit5];

Each one of those units has speciffic variable set by using setVariable command.

My question is how I can check (using getVariable command), which one of those units has that one variable I want?

Share this post


Link to post
Share on other sites

If so, then where's the problem here:

if !(isNil {{_x getVariable "101"} forEach units_array}) then {myCar setPos (position _x)};

Share this post


Link to post
Share on other sites
{
if(!isNil(_x getVariable "101")) then {
	myCar setPos (getPos _x);
};
} forEach units_array;

Share this post


Link to post
Share on other sites

There is one minor mistake with brackets in the upper code. Instead of '()' flanking getVariable command, there should be '{}', but it's good and now I have what I wanted.

Propper code:

{
   if(!isNil{_x getVariable "101"}) then {
       myCar setPos (getPos _x);
   };
} forEach units_array;

Thanks for the answers. Problem solved.

Share this post


Link to post
Share on other sites

Alternatively use the getVariable array

object getVariable [name, defaultValue]

Parameters:

object: Object or Location

name: String - Variable name that was defined in setVariable (Case sensitive)

defaultValue: Any Value - Value to return if variable doesn't exist

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
Sign in to follow this  

×