Tankbuster 1733 Posted November 6, 2015 This isn't as simple as the title suggests. I'm fiddling with house class objects being returned by nearobjects and need to make the result array a little more manageable. I'm sure this is computer studies 101, but when I did this in college, we started with 'environment division' and I'm a little rusty :) So, by way of example, how can I get from this; [tomato, apple, apple, apple, banana, banana, cranberry, tomato, tomato,tomato, apple, pear, pear, apple] to [[apple,5], [banana,2], [cranberry,1],[pear,2],[tomato,4]] Note the output is alpha sorted. I can see that a straightforward alpha sort of the input array is the first step, but how to count them and output like I want? Thanks in advance. :) Share this post Link to post Share on other sites
shuko 59 Posted November 6, 2015 If they are objects, then based on what value should they be sorted by? Share this post Link to post Share on other sites
killzone_kid 1326 Posted November 6, 2015 https://community.bistudio.com/wiki/BIS_fnc_consolidateArray 1 Share this post Link to post Share on other sites
Tankbuster 1733 Posted November 6, 2015 I saw that KK, you might notice my example uses fruit too, but I couldn't understand the wiki page. I'm assuming where it says 'duplicities', it means duplicates, which is what I want Share this post Link to post Share on other sites
Tankbuster 1733 Posted November 6, 2015 If they are objects, then based on what value should they be sorted by? alphabetically sorted by classname Share this post Link to post Share on other sites
Tankbuster 1733 Posted November 6, 2015 I may have been overthinking the biki page and have taken it at its most simplest. myarray2 = ["Land_i_House_Big_02_V2_F","Land_i_House_Small_02_V1_F","Land_PowerPoleWooden_L_F","Land_i_Addon_04_V1_F"] [myarray2] call BIS_fnc_consolidatearray returned [] Share this post Link to post Share on other sites
ProfTournesol 956 Posted November 6, 2015 And myarray2 call BIS_fnc_consolidatearray Share this post Link to post Share on other sites
Tankbuster 1733 Posted November 6, 2015 And myarray2 call BIS_fnc_consolidatearray Aha! There ya go! That's why they don't call ME prof. :) Share this post Link to post Share on other sites
shuko 59 Posted November 6, 2015 alphabetically sorted by classname Could have told us that you have an array of strings and not objects (like in your example). :rolleyes: Share this post Link to post Share on other sites
Tankbuster 1733 Posted November 6, 2015 Could have told us that you have an array of strings and not objects (like in your example). :rolleyes: I wasn't sure if was best to work with object names or classnames at the time. I've plumped for classsnames as they are more readable. Share this post Link to post Share on other sites
Tankbuster 1733 Posted November 6, 2015 So, here's the finished (ish) article. Thanks guys! myarray2 = []; myarray = player nearobjects ["House_F", 300]; {myarray2 pushback (typeof _x)} foreach myarray; myarray3 = myarray2 call BIS_fnc_consolidateArray; myarray3 sort true; {diag_log _x}foreach myarray3; Share this post Link to post Share on other sites