Jump to content
Sign in to follow this  
Blanco

Quick array question

Recommended Posts

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 or two line code with an if-then-else statement (probably with some _x stuff)?    rock.gif

Share this post


Link to post
Share on other sites
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 or two line code with an if-then-else statement (probably with some _x stuff)?    rock.gif

its better to not have different variable types in an array .. here u are mixing groups and units and then call it _units

i suggest u have one _units array and one _groups array

e.g.:

_units = [u1, u2, ...]

_groups = [g1, g2, ...]

_allunits = +_units (copy of _units)

{ _allunits = _allunits + (units _x) } forEach _groups

Share this post


Link to post
Share on other sites

AFAIK I can mix units & groups because every single unit is a group (it's just a group with 1 man)

Share this post


Link to post
Share on other sites

then this will do it:

_allunits = []

{ _allunits = _allunits + (units _x) } forEach _units

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×