OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Pimmelorus 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
-
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.
-
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?
-
1) 2 qoute dingers TUT
(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
-
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