Array.sort(function)

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Array.sort(function)

Postby rjgtav » 25 Aug 2010, 08:59

Hi guys. I've already found on the forums that the extensions don't support the array.sortOn method but they support the array.sort(). The problem is that to sort my array, i use a function but in the end, it sorts alphabetically.

Here's my code:

Code: Select all

function updateLeaderBoard(who){
   response = {};
   var sortList = [];
   for (var i in leaderBoardUsers){
      var user = leaderBoardUsers[i];
      uObj = {};
      uObj.name = user.getName();
      uObj.uId = user.getUserId();
      uObj.mod = user.isModerator();
      uObj.score = user.getVariable("score").getValue() * 1;
      sortList.push(uObj)
   }
   sortList.sort(orderScore)
}

function orderScore(user1, user2){
   if (user1.score < user2.score) {
      return 1;
   } else if (user1.score > user2.score) {
      return -1;
   } else {
      return 0;
    }
}


And if i trace anything in the orderScore, it traces correctly and I've already checked that it founds correctly that one score is bigger than the other.
Does anyone knows why it doesn't sort? Thanks in advance.
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 28 Aug 2010, 03:55

Humm from the looks of it you are using AS1 Extensions right? Well AS1 is actually just Javascript. A quick search on google and I found this:
http://www.kirupa.com/forum/showthread.php?t=325522
(It seems someone was also missing the sortOn on JS)

and this:
http://www.javascriptkit.com/javatutors/arraysort.shtml

Basically, on your future google searches, use "Javascript" as your keyword to find language related solutions. I also use AS1 extensions and this is how I always find the missing links =D

Hope that helps!
SELECT * FROM users WHERE clue > 0
0 rows returned.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 28 Aug 2010, 10:45

Hi. sorry, i forgot to tell that it started working for no reason.

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 10 guests