Thread: Sorting
View Single Post
  #9  
Old 11-20-2009, 09:15 PM
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
Well here's a little example on how to use sortbyvalue, it seems tricky due to the lack of documentation but it's quite simple overall. (Didn't see cbk posted this already but oh well..)

The syntax provided by script help, edited for clarity. (On RC: /scripthelp sortbyvalue).

TGraalVar.sortbyvalue(str1, str2, boolean) - sorts an array.
str1: the variable of the array members which is compared
str2: variable type; variable type can be "string", otherwise it is sorted by floating point value
boolean: sort by ascending (I.e: 1 to 9) or not

Usage:

PHP Code:
function onCreated() {
  
// Initialize Example Array
  
temp.arr = {{"a"33}, {"b"11}, {"c"22}};
  
// Loop through Array and specify Sortvalue
  
for (temp.atemp.arr) {
    
// Stores the Number in Sortvalue
    
temp.a.sortvalue temp.a[1];
  }
  
// Sort by Value
  
temp.arr.sortbyvalue("sortvalue"nulltrue);
  
// Echo Sorted Array
  
for (temp.atemp.arr) {
    echo(
temp.a[0SPC temp.a[1]);
  }
  
/*
     Echos
     b 11
     c 22
     a 33
  */

Like you posted above you can loop through your array that you created using getdynamicvarnames, and specify the sortvalue. So instead of using temp.a[1] like I did in the example you'd use the guild's/user's kills, which can be accessed like so:

PHP Code:
function onCreated() {
  
// Initialize Array and Kills Structure
  
this.guilds = {"a""b""c"};
  
this.guilds.a.kills 100;
  
this.guilds.b.kills 300;
  
this.guilds.c.kills 50;
  
// Loop and Display Kills
  
for (temp.gthis.guilds) {
    
temp.kills this.guilds.(@temp.g).kills;
    echo(
temp."'s kills: " temp.kills);
  }

__________________
Quote:

Last edited by fowlplay4; 11-20-2009 at 09:39 PM..
Reply With Quote