Jump to content
Sign in to follow this  
Fuzzy Bandit

Naming Multiple Variables inside a forEach Loop

Recommended Posts

Yeah, your loop is trying to allowDamage false on the [flag1, tflag1] array, which is obviously not legal and will give you an error. Instead, do the allowDamage false; on _flag and _tflag as shk demonstrated.

Share this post


Link to post
Share on other sites

Aye, unfortunately as I expected it would. Is there any way to select only the first expression?

I know about such things as ((_this select 0) select 0), but not sure about how to do that dynamically with a forEach loop.

Maybe just:

myFlags = [[flag1, tflag1], [flag2, tflag2], [flag3, tflag3]];

for [{_x = 0}, {_x <= (count myFlags)}, {x++}] do {
_flagname = ((myFlags select _x) select 0);
_flagname setVehicleInit "this allowDamage false";
};

Also, am I right in thinking that:

_flagname = call compile format ["flag%1", _x];  //Will return [i]_flagname = flag1[/i]
_flagname format ["flag%1", _x];    //Will return [i]_flagname = "flag1"[/i]

Edited by Fuzzy Bandit
Forgot CODE tag and entered wrong code...

Share this post


Link to post
Share on other sites

forEach will iterate over the array elements, in your case the [flagN, tflagN] arrays. So _x select 0 will refer to flagN.

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  

×