Page 1 of 1
Sorting alphabetically
Posted: Thu May 04, 2006 3:49 pm
by Aeros
Funnily enough, I've never done this in 3 years, but it's becoming an issue now:
How can you sort the resultset of EnumerateOnlineCharacters() alphabetically?
Posted: Thu May 04, 2006 4:32 pm
by tekproxy
Using the .sort() method.
Code: Select all
var chars := EnumerateOnlineCharacters();
chars.sort();
Posted: Thu May 04, 2006 4:34 pm
by Aeros
You mean I've been missing that all along?
Lol. Thanks tekproxy

Posted: Thu May 04, 2006 4:42 pm
by tekproxy
Think lazy, someone else already has and they're probably a core dev.
Posted: Thu May 04, 2006 4:44 pm
by Austin
Code: Select all
const SORT_ASCENDING := 0x0; // Default
const SORT_DESCENDING := 0x1;
//
// EnumerateOnlineCharactersABC()
//
// * Returns an list of player-refs, sorted by 'player.name'
//
function EnumerateOnlineCharactersABC( dir := SORT_ASCENDING )
var dict := dictionary;
var zList := EnumerateOnlineCharacters();
foreach player in zList
var key := upper(player.name);
if ( !dict.Exists(key) )
dict[key] := array();
endif
dict[key].append(player);
endforeach
zlist := array;
foreach key in (dict.keys())
foreach name in (dict[key])
if ( dir == SORT_ASCENDING )
zList.append(name);
else
zList.insert(1, name);
endif
endforeach
endforeach
return zList;
endfunction
Posted: Thu May 04, 2006 4:48 pm
by Aeros
Thanks Austin, I also stumbled across this now, from the old TSSE shard scriptset

Posted: Thu May 04, 2006 5:58 pm
by tekproxy
Sorry, I misunderstood what you wanted. Heh.
Posted: Thu May 04, 2006 6:02 pm
by Aeros
Lol yea I figured after awhile that that couldn't be it

sorting references wouldn't work as it wouldn't know what to sort by. Thanks anyway though

And thanks Austin.
Posted: Fri May 05, 2006 8:42 am
by MuadDib
Wonder if it shouldn't do it by defualt....... although, that means more work than I want to do on my lunch break
Who knows, maybe in 097, look into adjusting the .sort member for arrays to work more like php, but, don't hold me to it

Posted: Fri May 05, 2006 12:17 pm
by Aeros
Aw, you know you want to

Posted: Fri May 05, 2006 12:22 pm
by Yukiko
*chuckles*
Maud we have to get to 096 official release before we start thinking about 097.
BTW once again let me say thanks for your work you guys.