Sorting lists?

Freeform discussion about anything related to modding Transcendence.
Post Reply
Bobby
Militia Captain
Militia Captain
Posts: 675
Joined: Wed Jul 25, 2007 7:39 pm

Can a list be sorted? if so how?

Specifically I want to sort a list of lists, based on data within the lists.


the result of this should be sorted alphabetically

Code: Select all

(block (name unid known sov)
	(setq name (objGetName station 1))
	(setq unid (staGetType station))
	(setq known (if (objIsKnown station) "known" "unknown"))
	(setq sov (objGetSovereign station))
	
	(lnkAppend list (list name unid known sov (objGetID station)));
	
)
If alphabtecal sorting is not possible, how about sorting by level? (for a list of items)
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

There is no built in functions for sorting lists. I built one for DSF which work pretty good (along the same principle as the built in filter). You can have a look at it here, and feel free to copy the relevant bits out. Any questions on how it works or such, just ask here.

P.S.: Using this function it is possible to sort lists of lists by any criteria (alphabetically or level or any other piece of data that can be compared)
Bobby
Militia Captain
Militia Captain
Posts: 675
Joined: Wed Jul 25, 2007 7:39 pm

Thanks alterecco, it works great.
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

cool. just remember to change the dsf_ namespace to avoid any clashes
Post Reply