View Single Post
  #1  
Old 01-15-2010, 06:37 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
sortbyvalue() bugged?

I just discovered sortbyvalue() today, but it seems to be extremely inconsistent.

Just playing around with it, I've come across cases where it doesn't sort correctly.

For example, this NPC:
PHP Code:
function onCreated() {
  
temp.ui = {
    {
"item2"1},
    {
"item1"1},
  };
  
//myfunc(temp.ui);
  
for(temp.0temp.temp.ui.size(); temp.i++) {
    
temp.ui[temp.i].sorted_by temp.ui[temp.i][0];
  }
  
temp.ui.sortbyvalue("sorted_by""string"true);
  echo(
temp.ui);
}
function 
myfunc(arr) {
  for(
temp.0temp.temp.ui.size(); temp.i++) {
    
temp.arr[temp.i].sorted_by temp.arr[temp.i][0];
  }
  
temp.arr.sortbyvalue("sorted_by""string"true);
  echo(
temp.arr);

If only one sortbyvalue() process is used, as above, it works perfectly. In other words, if you decide to use myfunc() and comment out the sorting in onCreated(), it works fine. The same for if you don't use myfunc().

However, if you use both (i.e., removing the commented myfunc() and running script), the array is no longer sorted.

Also, the following script outputs an incorrectly sorted array. It works if you remove the 'before' echo, however.
PHP Code:
function onCreated() {
  
temp.ui = {
    {
"item2"1},
    {
"item1"1},
  };
  echo(
"before: " temp.ui);
  for(
temp.0temp.temp.ui.size(); temp.i++) {
    
temp.ui[temp.i].sorted_by temp.ui[temp.i][0];
  }
  
temp.ui.sortbyvalue("sorted_by""string"true);
  echo(
"after: " temp.ui);

__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote