OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Mr.Peanut on 19 Oct 2005, 00:48:28

Title: Nested forEachs
Post by: Mr.Peanut on 19 Oct 2005, 00:48:28
Could someone please verify the syntax of the following 2 code lines?
e.g.
Code: [Select]
smb_List20 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]
{{[_x] exec "FOX2_HDConvAI.sqs"} forEach units (call format["gra_%1",_x])} forEach smb_List20

where gra_0 to gra_19 are groups.
Title: Re:Nested forEachs
Post by: Raptorsaurus on 19 Oct 2005, 01:10:54
I think You need a semi-colon:

Code: [Select]
{{[_x] exec "FOX2_HDConvAI.sqs"} forEach units; (call format["gra_%1",_x])} forEach smb_List20
Title: Re:Nested forEachs
Post by: Triggerhappy on 19 Oct 2005, 02:35:41
no, you don't want a semicolon, that is correct syntax
Title: Re:Nested forEachs
Post by: Raptorsaurus on 19 Oct 2005, 03:47:00
Yes, you are right, sorry, I thought "units" was another array name and you were trying to do two commands for the second "forEach".  Your syntax was correct!  Oops. :-X
Title: Re:Nested forEachs
Post by: Mr.Peanut on 20 Oct 2005, 18:19:07
Okay,

Next question in this vein.  What if a nested forEach needs two temporary variables i.e. _x.

Code: [Select]
{{_x doFire _y} forEach units grpA} forEach units grpB
Title: Re:Nested forEachs
Post by: UNN on 20 Oct 2005, 20:39:57
Okay,

Next question in this vein.  What if a nested forEach needs two temporary variables i.e. _x.

Code: [Select]
{{_x doFire _y} forEach units grpA} forEach units grpB

Just use:

Code: [Select]
{_y=_x ; {_x doFire _y} forEach units grpA} forEach units grpB
Title: Re:Nested forEachs
Post by: Triggerhappy on 21 Oct 2005, 02:18:58
so, are you trying to have something like this?
x1 -> y1
x2 -> y2
x3 -> y3
etc

where the arrow is shooting

so that each member of one group is shooting their corresponding unit from the other group? otherwise what you'll end up with is every unit looping through til the end of the other groups list and killing that one

there is no way to do what you're trying to do, if i'm right about what you're trying, with foreach, simply not possible
Title: Re:Nested forEachs
Post by: Mr.Peanut on 21 Oct 2005, 15:05:21
The code I posted was just a possible example.