How to Alphabetise Lists?

NickamonPoppytail

  • Posts: 1137
Is there any way to alphabetise the initial values in a list for organisational purposes? Thanks in advance :)
Upcoming Projects
Poppytail 5 and Pixeltail: Fifth and sixth main instalments in Poppytail series. A Game About Trimming Hedges: Final Version: An updated version of the original AGATH. One Million: Last-one-standing style small project. The Poppytales: Platformer boss rush with character collecting. Skies n' Fall: Boss rush shooter prequel to Rise n' Brawl. Precious: Weird platformer. Christmas Time 2: Sequel to Christmas Time 1.

Luyren

  • *
  • Posts: 2645
If you mean in the toolset, by setting the values in a list attribute, you don't. Removing all items from your list, then create your sorted list in a .txt file and importing that is the fastes option as far as I know.

If you mean in-game, with code: sorting list is not a simple matter, and several algorithms exist on that subject. You'll either have to create your own algorithm, probably with a lot of loops, or you can try your hand at this:

Quote
sort(f : T -> T -> Int) : Void
Sorts `this` Array according to the comparison function `f`, where `f(x,y)` returns 0 if x == y, a positive Int if x > y and a negative Int if x < y. This operation modifies `this` Array in place. The sort operation is not guaranteed to be stable, which means that the order of equal elements may not be retained. For a stable Array sorting algorithm, `haxe.ds.sort.MergeSort.sort()` can be used instead. If `f` is null, the result is unspecified.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

NickamonPoppytail

  • Posts: 1137
That's a shame. I wanted to be able to add to the list every so often and have it reorganise itself in alphabetical order to make sure I don't duplicate any items. Thanks anyway.
Upcoming Projects
Poppytail 5 and Pixeltail: Fifth and sixth main instalments in Poppytail series. A Game About Trimming Hedges: Final Version: An updated version of the original AGATH. One Million: Last-one-standing style small project. The Poppytales: Platformer boss rush with character collecting. Skies n' Fall: Boss rush shooter prequel to Rise n' Brawl. Precious: Weird platformer. Christmas Time 2: Sequel to Christmas Time 1.

merrak

  • *
  • Posts: 2675
You can use the Haxe built-in sort function (the code Luyren shared), and the character codes (https://api.haxe.org/String.html#charCodeAt) to build a comparison function.