Problem sorting an array

Just started using Construct 2? Post your questions here

Post » Mon Oct 10, 2016 10:01 am

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 !
B
24
S
5
G
1
Posts: 336
Reputation: 2,433

Post » Mon Oct 10, 2016 11:29 am

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.
B
46
S
15
G
73
Posts: 2,026
Reputation: 43,459

Post » Mon Oct 10, 2016 12:13 pm

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.
B
24
S
5
G
1
Posts: 336
Reputation: 2,433


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest