OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Luke on 29 Jun 2009, 23:35:10

Title: Foreach in foreach
Post by: Luke on 29 Jun 2009, 23:35:10
Hey guys, is the following syntax right?

Code: [Select]
_array=_this select 0;
_script=_this select 1;

{
_crew = crew _x;
{[_y] execvm "_script"} foreach _crew;
} foreach _array;

Thanx, as always.

Luke
Title: Re: Foreach in foreach
Post by: Spooner on 30 Jun 2009, 00:00:39
Inner loops of forEach will safely mask the value of _x from outer loops. Also, where you to pass the name of a script to your function, it would be passed directly to execVM, not passed as part of a string:
Code: [Select]
{
    _crew = crew _x; // _x refers to element of _array
    { [_x] execVM _script } foreach _crew; // _x refers to element of _crew
    hint str _x; // _x refers to element of _array
} foreach _array;