Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: sort array  (Read 3390 times)

0 Members and 1 Guest are viewing this topic.

hubertMichael

  • Regular poster
  • ***
  • Karma: 3
  • Offline Offline
  • Posts: 155
    • View Profile
    • Shadow Of Nebula - our point'n click adventure game
sort array
« on: May 01, 2013, 04:30:28 PM »

Hi

Is there any command do sort values in array?
Logged
Shadow Of Nebula fan page:

https://www.facebook.com/shadowofnebula

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: sort array
« Reply #1 on: May 01, 2013, 08:30:27 PM »

Not as far as I know. You will have to implement your own. You can find many algorithms for this on the web if you want something sophisticated.
Logged

hubertMichael

  • Regular poster
  • ***
  • Karma: 3
  • Offline Offline
  • Posts: 155
    • View Profile
    • Shadow Of Nebula - our point'n click adventure game
Re: sort array
« Reply #2 on: May 01, 2013, 08:44:08 PM »

I just did this:
http://en.wikipedia.org/wiki/Bubble_sort but it's not so fast... I thought that WME can do this for me much faster.
Logged
Shadow Of Nebula fan page:

https://www.facebook.com/shadowofnebula

2.0

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 217
    • View Profile
Re: sort array
« Reply #3 on: May 01, 2013, 09:02:15 PM »

I think that technically is very difficult (or even impossible) to implement sorting of arrays inside WME engine. Because the array can store in general any data types, not only numerical. And even data of different types in the same array. How to sort the array, in which first element is number, and second is string?

As for sorting argorythms, try to study this one: http://en.wikipedia.org/wiki/Quicksort
Java implementation of it (that can be easyly ported to WME script) can be founded here http://ru.wikipedia.org/wiki/%D0%91%D1%8B%D1%81%D1%82%D1%80%D0%B0%D1%8F_%D1%81%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: sort array
« Reply #4 on: May 02, 2013, 04:44:50 PM »

I just did this:
http://en.wikipedia.org/wiki/Bubble_sort but it's not so fast... I thought that WME can do this for me much faster.

Well, even if WME supported array sorting, it would use one of the well-known algorithms. The issue, as 2.0 correctly said, is that WME supports an array to have multiple data types. Therefore, WME would not be able to guarantee that an array you command it to sort will indeed be sorted. I guess this is one reason why Mnemonic chose to not implement array sorting. So, you should be careful to store elements of the same data type in your array.
How big will your array be? Will it have tens of elements, thousands, millions? If we are talking about tens or hundreds of elements, a bubble sort algorithm will take a very small amount of time to sort the array. If you have thousands or millions of elements in the array, then you should consider other algorithms.
Logged
 

Page created in 0.018 seconds with 23 queries.