Sorting an array

Get help using Construct 2

Post » Mon Mar 05, 2012 12:49 pm

Thanks R0J0hound & Yann!

@kyatric - could you add this to the sticky "How To" thread? Sorting is an issue quite often!
B
43
S
19
G
12
Posts: 723
Reputation: 13,946

Post » Mon Mar 05, 2012 12:58 pm

Added to the "Arrays" section.
Also @Ashley, I'd love for the array plugin to interface the js standard functions of arrays like pop, push, sort, etc...

That would make sorting and using arrays even easier and more powerful.Kyatric2012-03-05 12:58:53
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
258
S
89
G
48
Posts: 7,082
Reputation: 62,778

Post » Mon Mar 05, 2012 4:03 pm

It would be difficult to allow people to call array.sort without allowing them to provide a custom comparator function. The default sort in JS converts everything toString which can produce some bizarre results if you're not expecting it.
B
17
S
6
G
6
Posts: 113
Reputation: 4,161

Post » Mon Mar 28, 2016 3:44 pm

Just found this now, and as always R0J0 to the rescue. Thanks for the bubble sort tip!
B
13
S
1
Posts: 51
Reputation: 736

Post » Mon Apr 25, 2016 6:43 pm

Both are nice examples but it is kind of hard to with a 2D array.
I might not sure how to implement it based on the OP example.

thanks,
B
93
S
34
G
23
Posts: 389
Reputation: 19,653

Post » Mon Apr 25, 2016 7:56 pm

@jogosgratispro
For a 10x2 array for example, you'd have to swap around not only array.at(curX), but the other values too. But no matter, just use the sort action and don't worry about it.
B
83
S
27
G
69
Posts: 4,915
Reputation: 48,997

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests