LIST
Command¶
A List
is a type of Structure that stores a list of variables in it. The LIST
command either prints or crates a List
object containing items queried from the game. For more information, see the page about the List structure.
FOR
Loop¶
Lists need to be iterated over sometimes, to help with this we have the FOR loop, explained on the flow control page. The LIST
Command comes in 3 forms:
LIST.
When no parameters are given, the LIST command is exactly equivalent to the command:
LIST FILES.
LIST ListKeyword.
This variant prints items to the termianl sceen. Depending on the ListKeyword used (see below), different values are printed.
Available Listable Keywords¶
The ListKeyword in the above command variants can be any of the following:
Universal Lists¶
These generate lists
that are not dependent on which Vessel
:
Bodies
Targets
Fonts
List
of available font names for use with eitherStyle:FONT
orSkin:FONT
. This list includes everything that has been loaded into the game engine by either KSP itself or by one of the KSP mods you have installed.
Vessel Lists¶
File System Lists¶
These generate lists
about the files in the system:
Files
List
the items, both files and subdirectories, on the current Volume at the current directory (you have to use thecd("dir")
command to change directories first if you want to get a list of files under some other location.) (note below) The list contains items of typeVolumeItem
Volumes
Note
LIST FILES.
is the default if you give the LIST
command no parameters.
Examples:
LIST. // Prints the list of files (and subdirectories) on current volume.
LIST FILES. // Does the same exact thing, but more explicitly.
LIST VOLUMES. // which volumes can be seen by this CPU?
LIST FILES IN fileList. // fileList is now a LIST() containing :struct:`VolumeItem` structures.
The file structures returned by LIST FILES IN fileList.
are documented on a separate page.
The file list contains both actual files and subdirectories under the current directory level. You can use the
VolumeItem:IsFile
suffix on each element to find out if it’s a file or a subdirectory. If it is a file rather than a
subdirectory, then it will also have all the suffixes of VolumeFile
on it.
Here are some more examples:
// Prints the list of all
// Celestial bodies in the system.
LIST BODIES.
// Puts the list of bodies into a variable.
LIST BODIES IN bodList.
// Iterate over everything in the list:
SET totMass to 0.
FOR bod in bodList {
SET totMass to totMass + bod:MASS.
}.
PRINT "The mass of the whole solar system is " + totMass.
// Adds variable foo that contains a list of
// resources for my current vessel
LIST RESOURCES IN foo.
FOR res IN foo {
PRINT res:NAME. // Will print the name of every
// resource in the vessel
}.