Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 01-15-2010, 07:28 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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());
__________________
Quote:
Reply With Quote
  #3  
Old 01-15-2010, 07:27 PM
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
Quote:
Originally Posted by fowlplay4 View Post
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.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:02 AM.


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