Blanco 0 Posted June 10, 2005 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)? Â Â Share this post Link to post Share on other sites
cleanrock 0 Posted June 10, 2005 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)? Â Â 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
Blanco 0 Posted June 10, 2005 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
cleanrock 0 Posted June 10, 2005 then this will do it: _allunits = [] { _allunits = _allunits + (units _x) } forEach _units Share this post Link to post Share on other sites