Home   Help Search Login Register  

Author Topic: Nested forEachs  (Read 868 times)

0 Members and 1 Guest are viewing this topic.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Nested forEachs
« 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.
« Last Edit: 19 Oct 2005, 00:50:04 by Mr.Peanut »
urp!

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:Nested forEachs
« Reply #1 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

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Nested forEachs
« Reply #2 on: 19 Oct 2005, 02:35:41 »
no, you don't want a semicolon, that is correct syntax
« Last Edit: 19 Oct 2005, 02:36:34 by Triggerhappy »

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:Nested forEachs
« Reply #3 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

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re:Nested forEachs
« Reply #4 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
urp!

UNN

  • Guest
Re:Nested forEachs
« Reply #5 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

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Nested forEachs
« Reply #6 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

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re:Nested forEachs
« Reply #7 on: 21 Oct 2005, 15:05:21 »
The code I posted was just a possible example.
urp!