list forming query 2

Freeform discussion about anything related to modding Transcendence.
Post Reply
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Trying to get a list of docked ships at St Kats Arcology which have the attribute "D789FreighterWingmen".

Because the arcology is 12 different segments code like this, which works at "single" stations, doesn't work:

Code: Select all

(setq freightersDocked (filter (staGetDockedShips gSource) dockObj (objHasAttribute dockObj 'D789FreighterWingman)))
This code:

Code: Select all

(setq dockedShips (map (sysFindObject Nil 't +arcology;) 'excludeNil seg (staGetDockedShips seg)))
gives a list of lists of docked ships like this

Code: Select all

((162144776) (154743880 155825144 162128688) (162081352 154792160) (156979776 154716584 155783416) (404810576) (158687288) (154789592) (158683816 162099528) (154768960 154812272) (154792992 162090360) (165241312))
In this case there are 19 ships docked at 11 of the Arcology segments and one segment has no docked ships.

Unfortunately I have no idea how to turn this list of 11 lists into a single list to filter. Possibly it's a combination of append, enum, loop or lnkAppend but who knows!

Has anyone done this, know of a better way or can send me in the direction of an example?
Stupid code. Do what I want, not what I typed in!
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

Here are a couple options:

(enum listOfStations theStation (lnkAppend combinedListVar (staGetDockedShips theStation)))

EDIT: For future reference, as pointed out below, this has the same problem as your code. But these should work:

Code: Select all

(enum listOfStations theStation (setq combinedListVar (append combinedListVar (staGetDockedShips theStation))))
or

Code: Select all

(apply append listOfLists)
Last edited by NMS on Sat Aug 05, 2017 2:55 am, edited 2 times in total.
User avatar
0xABCDEF
Militia Lieutenant
Militia Lieutenant
Posts: 124
Joined: Thu May 19, 2016 12:58 am
Location: Was destroyed by a Phobos-class dreadnought in the Eridani system

The quickest solution

Code: Select all

(apply append theList)
Be aware of the following functions.

lnkAppend always uses the first argument as a reference to a list (a variable that represents a list) and appends the second argument as a single entry to the list.

Code: Select all

(block (theList)
	(setq theList (list 1 2 3))
	(lnkAppend theList (list 4 5 6))
	theList
	)
;Returns (1 2 3 (4 5 6))
append always returns a copy of the first argument and separates the following arguments into entries (if they are lists).

Code: Select all

(block (theList)
	(setq theList (list 1 2 3))
	(setq theList (append theList (list 4 5 6)))
	(setq theList (append theList 7 8 9))
	(setq theList (append theList (list (list 10 11 12) (list 13 14 15))))
	theList
	)
;Returns (1 2 3 4 5 6 7 8 9 (10 11 12) (13 14 15))
apply takes a function and a list and invokes the function with the entries of the list as the arguments

Code: Select all

(apply append (list 1 2 3 (list 4 5 6) (list (list 7 8 9))))
;Equivalent to (append 1 2 3 (list 4 5 6) (list (list 7 8 9)))
;Returns (1 2 3 4 5 6 (7 8 9))
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

The apply code works beautifully and is already included in the mod. And the explanations of the functions are excellent if a touch jargonish. This info is going in the "very useful stuff" folder. Thank you both very much.
Stupid code. Do what I want, not what I typed in!
Post Reply