supertux icon indicating copy to clipboard operation
supertux copied to clipboard

World select circle is out of order

Open weluvgoatz opened this issue 3 years ago • 1 comments

The world select circle should be displaying the 4 worlds in chronological order, like World 1 -> 2 -> 3 -> 4, but for some reason, the game instead lists them by 1 -> 4 -> 2 -> 3, which is completely out of order.

weluvgoatz avatar Aug 13 '22 23:08 weluvgoatz

Cause of the bug: Squirrel does not seem to preserve any kind of ordering for keys in objects. E. g., setting the world 1 before world 2, before world 2, before world 4, will not guarantee that when enumerating the properties of an object, they'll come out in order; that means each time, they might come out in a different order.

A (rather poor) solution would be to sort the world list after getting it from the object's keys. I say poor because sorting, unless some algorithm is given, would not work for any list of worlds that is not alphabetically ordered. For example, if the worlds are keyed as ['icy_island', 'rooted_forest', 'tropical_islands', 'mountain_peaks'], sorting them manually would sort them by alphabetical order, which still puts them out of order story-wise¹.

A better solution would be to find a different way to hold the worlds' data, such as within an array, which preserves ordering correctly. However, I didn't investigate very thoroughly if all the relevant points in the C++ code would be easy to adapt to this method.


¹: Knowing the team, there probably will be someone to say "but we just have to always keep them names like 'world1', 'world2' and so on", nobody to comment on such a proposal, and then that same person to proceed to implement it - without documenting it anywhere, which practically guarantees that whoever will make the next batch of developers won't know about it and, when they'll decide that it'd look cuter to key the worlds by their real names, will be lost as to why the order in the world select menu is wrong - assuming they'll realize it at all (how many months before even we noticed it?).

If such a decision is to be taken anyways, I would recommend instead to directly hardcode the world ordering somewhere in the code, such as in an enum or similar, so that at least whoever will have to maintain it in the future will see, notice and understand that it is hardcoded and it was not designed to be easily workable with any given set of world that differs from our vision of the story as of right now.

Semphriss avatar Aug 14 '22 02:08 Semphriss

By the way, I noticed that in earlier versions of the world select pull request, they were indeed in the proper order, so maybe something along the way of the PR happened that put them out of order?

weluvgoatz avatar Dec 20 '22 05:12 weluvgoatz