Array sorting

Discussion and feedback on Construct 2

Post » Thu May 11, 2017 7:38 am

Hi there,
I have an array that contains numbers
one problem with the sorting is that its does not read the whole value example

1.0
2.10
3.2

this is the result of sorting.
what i want is

1.0
2.2
3.10

Any idea how to accomplish it?
Thanks
B
12
S
3
Posts: 15
Reputation: 734

Post » Thu May 11, 2017 12:15 pm

Say, this '1.0'

1 is a value on (0,0) ?
0 is a value on (0,1) ?

or '2.10'

2 is a value on ((1,0) ?
10 is a value on ((1,1) ?

or does the 2 in '2.10' just stands for the X index and 10 is the value on that index ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu May 11, 2017 5:24 pm

@sebastiangohhy

You have to zero pad numbers if you want them to sort properly - the array sort does a text based sort.

so, when you put a number into the array use zeropad(number,digits)

when you need to use then number later, convert it back to a number using int(arrayvalue) or float(arrayvalue)...
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Fri May 12, 2017 4:56 am

@AllanR
THANK YOU, exactly what i needed
B
12
S
3
Posts: 15
Reputation: 734


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 33 guests