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
44
S
23
G
13
Posts: 723
Reputation: 14,925

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
289
S
112
G
94
Posts: 7,333
Reputation: 69,293

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
21
S
6
Posts: 77
Reputation: 1,445

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
116
S
49
G
24
Posts: 401
Reputation: 22,257

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
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Previous

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Nicolas951, R0J0hound and 10 guests