Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-07-2011, 08:49 PM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
this.array.sortascending() Help?

Hello,
I realize that sortascending() sorts from least to greatest, but I am having a problem when the greatest is over single digits. I'm guessing that it only reads the first digit to place the item into the array, and I don't see another way around this. Any suggestions would be appreciated!
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #2  
Old 01-07-2011, 11:16 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by Stefan View Post
Quoting http://forums.graalonline.com/forums...81&postcount=2 :

For the tree view you set attributes like this:

sortmode = "value";
sortorder = "descending";
groupsortorder = "ascending";

For the nodes then:

sortvalue = 1;
sortgroup = 2;

That would sort the nodes after the value you have assigned to them. When you set sortmode="name" then it will be sorted alphabetically. The sort group can be used to let some types of nodes always appear at the top, e.g. in a folder view you would want to display the folders at the top.

---

sortmode can be "value", "name" or "extension"
You basically assign a value to each entry adn sort by value.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #3  
Old 01-07-2011, 11:32 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by xXziroXx View Post
You basically assign a value to each entry adn sort by value.
Uh, this works for sortascending? I thought it was for GUIs.


The problem is that it is sorting by the string value, rather than the number value.
i.e.,
{"aaa", "aab", "ba", "c"} is sorted by the string value.
{111, 112, 21, 3} is sorted by the string value, when it should really be sorted by float value into: {3,21,111,112}.


To my knowledge there are two ways to solve this:

Way 1
Store the number in a subvariable for each item in the array, then use sortbyvalue:
PHP Code:
temp.xs = {1,6,7,3,2,1,5,23,41,75,2347,51,123};

for (
temp.0temp.temp.xs.size(); temp.i++) {
  
temp.xs[temp.i].blah temp.xs[temp.i];
}
temp.xs.sortbyvalue("blah""float"true); 
Way 2
Use quicksort, which lets you specify your own function for comparing two values. (See examples in the link.)
Reply With Quote
  #4  
Old 01-07-2011, 11:59 PM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Quote:
Originally Posted by WhiteDragon View Post
Uh, this works for sortascending?
Way 1
Store the number in a subvariable for each item in the array, then use sortbyvalue:
PHP Code:
temp.xs = {1,6,7,3,2,1,5,23,41,75,2347,51,123};

for (
temp.0temp.temp.xs.size(); temp.i++) {
  
temp.xs[temp.i].blah temp.xs[temp.i];
}
temp.xs.sortbyvalue("blah""float"true); 
This worked for me, but I'm unsure why the .blah was needed when assigning. I'm not sure if the other is for GUIs or not, but thanks for the help!
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #5  
Old 01-08-2011, 12:07 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by WhiteDragon View Post
Uh, this works for sortascending? I thought it was for GUIs.
Oops, seems I misunderstood the OP.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #6  
Old 01-08-2011, 12:08 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
Quote:
Originally Posted by kingcj View Post
This worked for me, but I'm unsure why the .blah was needed when assigning. I'm not sure if the other is for GUIs or not, but thanks for the help!
That's the variable sortbyvalue grabs the value from to sort it by, you could use rabblerabble if you wanted to.

I.e:

PHP Code:
temp.xs = {1,6,7,3,2,1,5,23,41,75,2347,51,123}; 
for (
temp.0temp.temp.xs.size(); temp.i++) { 
  
temp.xs[temp.i].rabblerabble temp.xs[temp.i]; 

temp.xs.sortbyvalue("rabblerabble""float"true); 
__________________
Quote:
Reply With Quote
  #7  
Old 01-08-2011, 12:37 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Quote:
Originally Posted by fowlplay4 View Post
That's the variable sortbyvalue grabs the value from to sort it by, you could use rabblerabble if you wanted to.

I.e:

PHP Code:
temp.xs = {1,6,7,3,2,1,5,23,41,75,2347,51,123}; 
for (
temp.0temp.temp.xs.size(); temp.i++) { 
  
temp.xs[temp.i].rabblerabble temp.xs[temp.i]; 

temp.xs.sortbyvalue("rabblerabble""float"true); 
Oh... Thank you very much!
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 07:16 AM.


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