Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   sortbyvalue() bugged? (https://forums.graalonline.com/forums/showthread.php?t=134257664)

LoneAngelIbesu 01-15-2010 06:37 AM

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);



fowlplay4 01-15-2010 07:28 AM

You try passing the linked array? Personally I've never had a problem but I've only had to do one sort at a time.

I.e: myFunc(temp.arr.link());

LoneAngelIbesu 01-15-2010 07:27 PM

Quote:

Originally Posted by fowlplay4 (Post 1550509)
You try passing the linked array? Personally I've never had a problem but I've only had to do one sort at a time.

I.e: myFunc(temp.arr.link());

It makes no difference. If more than one sortbyvalue() is used at a time (even if in different functions), the sorting no longer works.


All times are GMT +2. The time now is 04:27 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.