Jump to content
Sign in to follow this  
CarlGustaffa

forEach in conditions

Recommended Posts

Hi

I hae a trigger where I'm trying to determine if my whole squad is in. I can't (in this particular case) use a linked-to-unit trigger.

Can I use forEach loops in a condition? If so, how?

Tried something in the realms of:

({_x in uVeh} forEach units uMyGroup)

but the editor won't accept it.

Do I really have to test each single unit? What if he's dead already?

Share this post


Link to post
Share on other sites

Set the trigger, close it, then select group on the right and drag a line from the trigger to the group leader.

Then open the trigger and select "Whole Group" in the dropdown. And set it to present. If the whole group is present the trigger will be active.

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">({_x in (crew uVeh)} count (units uMyGroup))==count (units uMyGroup)

or in a script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vehUnits=crew uVeh; _units=units uMyGroup;

myGroupCondition=(({_x in _vehUnits} count uMyGroupUnits)==count _units);

myGroupCondition will then either be false or true

what also might work in the condition is this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">myGroupCondition=true; { if ( !(_x in (crew uVeh)) ) then { myGroupCondition=false } } forEach (units uMyGroup); myGroupCondition

But I guess the first option is the easiest.

Share this post


Link to post
Share on other sites
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">({_x in (crew uVeh)} count (units uMyGroup))==count (units uMyGroup)

icon_rolleyes.gif

({!(_x in (crew uVeh))} count (units uMyGroup))==0

Share this post


Link to post
Share on other sites

I know you problem seems to be solved, but as a general note: A condition can either be true or false, hence the expression/variable in the condition field has to return such type of value (via e.g. comparison operations) or the variable has to be of type boolean. Loops don't return anything per se.

Share this post


Link to post
Share on other sites

Thanks a lot. Looking forward to try this when I get home. Who ever invented so long work hours? whistle.gif

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  

×