Home   Help Search Login Register  

Author Topic: array question again  (Read 647 times)

0 Members and 1 Guest are viewing this topic.

Offline Blanco

  • Former Staff
  • ****
array question again
« on: 10 Jun 2005, 07:14:22 »
When I have an array with units and groups like :

_units = [unit1,unit2,grp1,grp1,grp3]

...what is the fastest and easiest way to put every single unit in new array (_allunits =[]) ?
So when grp1,grp2 and grp3 contains 4 units ,_allunits should store 14 units (4+4+4+2=14)
I always do it with a cycle loop but is there a one line code with an if-then- else statement?   :-\


Search or search or search before you ask.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:array question again
« Reply #1 on: 10 Jun 2005, 07:49:30 »
You mean like:

array = (units grp1) + (units grp2) + (units grp3) + (units grp4) + [unit1, unit2, bob, bob's mum, uncle arthur]

?

I'm not too sure I've understood the question quite right ;)

UNN

  • Guest
Re:array question again
« Reply #2 on: 10 Jun 2005, 12:22:30 »
Unless you know exactly what groups your dealing with, I think your always going to have to use some sort of loop. But you can keep it down to just one:

Code: [Select]
_NewUnits=[]
{_Temp=Units _x ; If !(_x In _Temp) Then {_NewUnits=_NewUnits+_Temp} Else {_NewUnits=_NewUnits+[_x]}} ForEach _Units

The if condition checks if your dealing with a group or a single unit, and acts accordingly.

Offline Blanco

  • Former Staff
  • ****
Re:array question again
« Reply #3 on: 21 Jun 2005, 04:36:29 »
It works, thx a lot UNN  ;)
 
Search or search or search before you ask.