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
42
S
19
G
12
Posts: 723
Reputation: 13,911

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
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

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
11
Posts: 44
Reputation: 522

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
85
S
31
G
22
Posts: 384
Reputation: 18,592

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
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Previous

Return to How do I....?

Who is online

Users browsing this forum: jeffige, Mallets and 30 guests