Problem sorting an array

  • This is really a beginner thing but for some reason I'm unable to do it.

    I created an array with 5 X values to stock the high scores. The array is working correctly and I can see the values in the inspector.

    I ask to sort the array (array > Sort X axis), it is a one-dimensional array (width 5, height 1, depth 1), but nothing is sorted.

    Values are still 160, 21, 212, 46, 75

    After injecting 552, the array is now (after being sorted) : 21, 212, 45, 552, 75

    After injecting 1067, the array is now 1067, 212, 45, 552, 75

    My conclusion is that every entry is reduced to the first 2 numbers (552 is 55.2, 212 is 21.2, 1067 is 10.67) but I'm not asking for this in my code (unless I'm really missing something here). But anyway, in the inspector, values are displayed correctly as 552 and 212 so I guess the sorting should be correct.

    I've perfomed a test with a very simple project, injecting values at random in an array then sorting everything. It obviously works perfectly fine. So now I'm really scratching my head to know why my array wouldn't sort, even when I'm on doing it every tick on a layer which doesn't do anything else... :-/

    Any idea of what I'm doing wrong?

    Thanks !

  • The only way I can see that it's doing that is if you put the numbers in quotation marks which means they're now strings and it's sorting them alphabetically by first digit.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks a lot, you most probably found my problem as following this video by ArcadEd, I created a text variable to store all my scores as a text string, then getting scores back from the string with tokenat.

    Now I guess I need to do something to get the values back in numbers, but I probably missed this step in the video.

    At least I understand where the problem is! Thanks!

    EDIT : It's fixed. I just needed to add int( before the tokenat expression.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)