Home   Help Search Login Register  

Author Topic: Foreach in foreach  (Read 1194 times)

0 Members and 1 Guest are viewing this topic.

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Foreach in foreach
« 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
Pesky Human!!
Wort Wort Wort.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Foreach in foreach
« Reply #1 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;
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)