Home   Help Search Login Register  

Author Topic: (foreach (foreach))....  (Read 1071 times)

0 Members and 1 Guest are viewing this topic.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
(foreach (foreach))....
« on: 06 Mar 2005, 15:16:52 »
if you know what i mean :P

mkay - i am dynamically creating variables using the format command. what i would like to do is dynamically create those variables for each of the loons in a group. i don't even know if nested format/foreach commands are possible, but frankly the syntax is doing my nut in.

to be more specific, i'd like to store the position of each loon in a group in a dynamically created variable. i could do it by hand - in fact i have - but the problem is that the number of loons in the group is random, so i never know how many variables to create...

ideas?
« Last Edit: 06 Mar 2005, 15:17:35 by bedges »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:(foreach (foreach))....
« Reply #1 on: 06 Mar 2005, 15:52:58 »
Why use forEach??
Easier to use while/do loop or regular goto loop for that...

Now this example will not work as is on your stuff but should give you the idea...:

Code: [Select]
_grp=units group _this
_i=0

while "_i<count _grp" do {format ["MyVarib_%1",_grp select _i]; _i=_i+1}
 

Or something like that...
« Last Edit: 06 Mar 2005, 15:53:35 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:(foreach (foreach))....
« Reply #2 on: 06 Mar 2005, 16:11:45 »
yes indeed, i had started down the looping track a short while ago - i have successfully got the names being stored and returned... so far so good ;)

the while option is somthing i hadn't considered. thanks for the input, i'll put that to the test.

cheers meantime :)

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:(foreach (foreach))....
« Reply #3 on: 07 Mar 2005, 04:38:29 »
Afaik, you can't dynamically create variables. You have to declare them first. So, depending on how many variables you wanted to create, you'd have to type:
MyVarib_1=NIL (Or whatever)
MyVarib_2=NIL
... etc
before the code will work.

EDIT: whoops, you say it is working. Never mind. ;)
« Last Edit: 07 Mar 2005, 04:39:29 by Fragorl »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:(foreach (foreach))....
« Reply #4 on: 07 Mar 2005, 11:20:40 »
well, working yes and working no. i still hadn't gotten around the problem you've just outlined, that i'd need to declare the variables first before doing anything to them.

i notice in another thread that what i need to do is pretty much impossible - and (it seems) illogical, captain - as i need the editor-defined names of the loons to be able to access them. using group player select _i spits out 'WEST Alpha Black:6' or whatever, which naturally throws up an error.

i got the overall effect i wanted though. the initial intention was to be able to teleport a group, in formation. thus, i needed the x/y offset to be stored and retrieved, but all depending on how many loons there were in any group.

the shoddy workaround i've arrived at is using the player as the setpos centre and using a randomised sin/cos to throw the loons around him/her. they soon drift back into formation, and (so far) there haven't been any messy collisions. i did want to setpos them in a perdy circle, but then i'd have to increment the angle according to their number in the group, which brings us back to the first problem.

meh. it works. i'll leave it at that. thanks for the input anyways :)