Sort arbitrary items with no fuss

Monkey Forums/Monkey Code/Sort arbitrary items with no fuss

Gerry Quinn(Posted 2013) [#1]
[Edit: I rewrote this adding a more general sorting function]


Ever had an array of objects that you'd like to tackle in a particular order based on some property but you haven't sorted them that way and you don't want to? For example, suppose creatures in a dungeon are listed in order of which will move first, but occasionally you want to cast a spell that affects everyone in order of size.

Let us hypothesise further that you don't want to have to make generic classes to help with sorting.

Then this module may be for you!


sortitems.monkey



Example using it:




Note that nothing happens to your original data, you just get a list that you can use to do each item in order.

If you are using the SortArray function and the number of values does not match the number of items, an empty list will be returned.


Gerry Quinn(Posted 2013) [#2]
Just to note: I edited the above today to include a more general sorting functionality.