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
13
Posts: 723
Reputation: 14,535

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
262
S
93
G
54
Posts: 7,139
Reputation: 66,547

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: 52
Reputation: 738

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
96
S
35
G
23
Posts: 389
Reputation: 19,842

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
85
S
27
G
77
Posts: 5,000
Reputation: 53,734

Previous

Return to How do I....?

Who is online

Users browsing this forum: Daggio, Iftikhar555, stuffinabox and 7 guests