OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Blanco on 10 Jun 2005, 07:14:22

Title: array question again
Post by: Blanco 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?   :-\


Title: Re:array question again
Post by: Sui 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 ;)
Title: Re:array question again
Post by: UNN 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.
Title: Re:array question again
Post by: Blanco on 21 Jun 2005, 04:36:29
It works, thx a lot UNN  ;)