Home   Help Search Login Register  

Author Topic: "forEach" command question  (Read 621 times)

0 Members and 1 Guest are viewing this topic.

Pimmelorus

  • Guest
"forEach" command question
« on: 26 Jun 2003, 12:48:24 »
Hi all,

As i am advancing in my scripting skills I am starting to thing about more complex ways of scripting. For now I come up with two questions that are related to the "forEach"-command.

Question #1:
I came across this snipit in Dingers OFPEC Variable tutorial

tempnum = 0
"Format [""dude%1 = units group player select tempnum"", tempnum]; ForEach [ 0]; tempnum = tempnum + 1" ForEach units group player


What is the function of the "ForEach [ 0]"? I think it it something crucial and might be the key to many of my unsuccesful attempts in using more complex stuff with the "format" command.


Question #2
Are conditional actions (if...then...) possible in "forEach" command lines. I mean like this:

{?side _x == east: _x setDammage 1} forEach _allunits


(nothing usefull, just an example). If this works is a special syntax required?

Question #3
Can {..} be used like "..." to pass the first part of the "forEach" command?

Thnx for your time,

Pimmelorus

« Last Edit: 26 Jun 2003, 12:51:33 by Pimmelorus »

deaddog

  • Guest
Re:"forEach" command question
« Reply #1 on: 26 Jun 2003, 15:21:58 »
Q1:  Don't know about that.  It seems that the Foreach
  • is missing the rest of the code for it.  Also, if you are trying to create variables with the format function, then try use "call format...".


Q2:  Yes.  This is the correct syntax:
{if (side _x == east) then { _x setDammage 1}} forEach _allunits

I'm not sure if your way works because I always use the "if" statement.


Q3:  { and " are interchangeable.


Here's a rather ugly example of foreach.  This is the onactivation line of a "East present" trigger which covers three spetz naz teams.  I wanted to change their weapons by removing the satchel charges and adding handgrenades and Scorpions.  As you can see, it has nested foreach commands.

expActiv="{_su=_x;_b=magazines _x;{_su removeMagazine ""pipebomb"";if ({_x==""HandGrenade""} count magazines _su <4) then {_su addMagazine ""handgrenade"";_su addMagazine ""Skorpionmag""}} foreach _b;_x addWeapon ""skorpion""} forEach thislist";


Ugly... yes, effective... yes.  One line to change the weapons for three, four man squads.  It removes the three satchel charges, adds four handgrenades and four scorpion mags and one scorpion.  But does not touch the primary weapon.
« Last Edit: 26 Jun 2003, 15:40:44 by deaddog »

Pimmelorus

  • Guest
Re:"forEach" command question
« Reply #2 on: 26 Jun 2003, 17:47:41 »
Thnx for replying. I have seen the

forEach [ o] (without space)

in other scripts too, so I assume there is more to it than an error. Can anyone help?

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:"forEach" command question
« Reply #3 on: 26 Jun 2003, 18:25:48 »
1) 2 qoute dingers TUT

Quote
(As I write this, I know of nobody else who uses them)

so i guess u wil have 2 ask da 1 n only himself ;) :P

but as i work w/ da format command here n dere - i dont think its realy nesecary unless u work w/ realy complex things - wat r tryin 2 do ? mebe we can help u on dat ;)

DD gotda oder 2 Qs

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Pimmelorus

  • Guest
Re:"forEach" command question
« Reply #4 on: 27 Jun 2003, 12:19:54 »
Ok I spoke to Tactician and he answered all my questions. I want to share these with you all also for archiving perpouses:

ad Question #1:

The "forEach [ 0]"  code was the pre-OFP1.85 version of the "call" command. Therefore I conclude that this is code obsolete and should not be applied anymore


ad Question #2:

Conditional formating with the "forEach" command is possible, but you are forced to use an other syntax:

"IF (side _x == east) THEN {_x setDammage 1}" forEach _unitslist

Note the use of "IF" and "THEN" acompanied by the use of "(...)" and "{...}" for the condition and action, respectively (see comref)

Bye and thnx to Tacticial and all that have replied,

Pimmelorus