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:

  1. LIST.

    When no parameters are given, the LIST command is exactly equivalent to the command:

  2. LIST ListKeyword.

    This variant prints items to the termianl sceen. Depending on the ListKeyword used (see below), different values are printed.

  3. LIST ListKeyword IN YourVariable.

    This variant takes the items that would otherwise have been printed to the terminal screen, and instead makes a List of them in YourVariable, that you can then iterate over with a FOR loop if you like.

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:

List of Celestial Bodies
List of possible target Vessels
List of available font names for use with either Style:FONT or Skin: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

These generate lists of items on the Vessel:

List of Processors
List of AggregateResources
List of Parts
List of Engines
List of Sensors
List of Elements that comprise the current vessel.
list of DockingPorts <DockingPort>

File System Lists

These generate lists about the files in the system:

List the items, both files and subdirectories, on the current Volume at the current directory (you have to use the cd("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 type VolumeItem
List all the volumes that exist.


LIST FILES. is the default if you give the LIST command no parameters.


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.

// Puts the list of bodies into a variable.
// 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
FOR res IN foo {
    PRINT res:NAME. // Will print the name of every
                    // resource in the vessel