Sorting alphabetically

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

Sorting alphabetically

Post 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?
User avatar
tekproxy
Forum Regular
Posts: 352
Joined: Thu Apr 06, 2006 5:11 pm

Post by tekproxy »

Using the .sort() method.

Code: Select all

var chars := EnumerateOnlineCharacters();
chars.sort();
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

Post by Aeros »

You mean I've been missing that all along? O_o

Lol. Thanks tekproxy :)
User avatar
tekproxy
Forum Regular
Posts: 352
Joined: Thu Apr 06, 2006 5:11 pm

Post by tekproxy »

Think lazy, someone else already has and they're probably a core dev.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post 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
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

Post by Aeros »

Thanks Austin, I also stumbled across this now, from the old TSSE shard scriptset :)
User avatar
tekproxy
Forum Regular
Posts: 352
Joined: Thu Apr 06, 2006 5:11 pm

Post by tekproxy »

Sorry, I misunderstood what you wanted. Heh.
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

Post by Aeros »

Lol yea I figured after awhile that that couldn't be it :P sorting references wouldn't work as it wouldn't know what to sort by. Thanks anyway though :) And thanks Austin.
MuadDib
Former Developer
Posts: 1091
Joined: Sun Feb 12, 2006 9:50 pm

Post 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 :P
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

Post by Aeros »

Aw, you know you want to :P
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post 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.
Post Reply