Home   Help Search Login Register  

Author Topic: multiline foreach???  (Read 1531 times)

0 Members and 1 Guest are viewing this topic.

Offline Acecool

  • Members
  • *
multiline foreach???
« on: 04 Aug 2008, 19:37:57 »
Is it possible to do something like

Code: [Select]
foreach array as _variable
{
      ? (this select 0 == Player) && (this select 0 distance < 100 from workzone) : {_variable}_money+=civ_paycheck
};

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: multiline foreach???
« Reply #1 on: 07 Aug 2008, 10:46:54 »
* Use forEach , which puts the iterated value into the special variable, _x (you can use this on one line in SQS, which is line-based, but you can spread it on multiple lines in SQF).
* You can't use ?: inside {} or in an SQF script, so you have to use if/then/else.
* You also don't have += defined in the parser, and have to do that manually.
* I have no idea what you are trying to achieve with "{_variable}_money", but I'd guess you want to use dynamic code to generate the variable-name.
* I assume you mean to use _this, rather than this.

Code: (SQF script) [Select]
{
    if (((_this select 0) == Player) && (((_this select 0) distance workzone)  < 100)) then
    {
        call format ["%1_money = %1_money + civ_paycheck", _x];
    };
} forEach array;

I'd worry about learning the simple end of scripting syntax before worrying too much about forEach and dynamic code generation.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)