Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   sortsub() (https://forums.graalonline.com/forums/showthread.php?t=86577)

DustyPorViva 06-27-2009 11:23 PM

sortsub()
 
.sortsubascending(index)
.sortsubdescending(index)

Will sort an array from the index provided in the subarrays.

Example:
this.test = {{"one",1},{"five",5},{"three",3},{"four",4},{"two ",2}};

this.test.sortsubascending(1);


Will return:
this.test = {{"one",1},{"two",2},{"three",3},{"four",4},{"five ",5}};

I'm not exactly sure of the syntax, but I'd like to see some way for this to be easily done.

Chompy 06-27-2009 11:34 PM

so basicly

temp.array.sortsubascending(index)
temp.array.sortsubdescending(index)

temp.array.subarray(index).sortascending()
temp.array.subarray(index).sortdescending()


Wouldn't something like that work?

Edit: Nevermind, Wouldn't work as I don't think they return anything..?

napo_p2p 06-27-2009 11:38 PM

This kind of thing is possible if you use an array of TStaticVars and use sortbyvalue().

Quick Example:
PHP Code:

function OnCreated() {
  
temp.test = {arrayMember("one"1), arrayMember("five"5), arrayMember("three"3), arrayMember("four"4), arrayMember("two"2)};
  
temp.test.sortbyvalue("num"nulltrue);  //Sorts the 'num' values by floating point value (ascending)
  
  
for (temp.membertemp.test) {
    echo(
temp.member.num SPC temp.member.text);
  }
}

function 
arrayMember(textnum) {
  
temp.result = new TStaticVar();
  
temp.result.text temp.text;
  
temp.result.num temp.num;
  return 
temp.result;


Result:
NPC Code:
1 one
2 two
3 three
4 four
5 five


DustyPorViva 06-27-2009 11:45 PM

Quote:

Originally Posted by Chompy (Post 1502248)
so basicly

temp.array.sortsubascending(index)
temp.array.sortsubdescending(index)

temp.array.subarray(index).sortascending()
temp.array.subarray(index).sortdescending()


Wouldn't something like that work?

Edit: Nevermind, Wouldn't work as I don't think they return anything..?

If that did work, it would simply sort the data in the subarray. What I'm suggesting is a way to sort the array, from data within a subarray.

Admins 07-20-2009 01:27 AM

The easiest way to sort such arrays right now is to set an attribute of each array member (temp.array[i].sortvalue = temp.array[i][1]) and then use sortbyvalue (temp.array.sortbyvalue("sortvalue","int",true))


All times are GMT +2. The time now is 12:03 AM.

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