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 4 forms:

  1. LIST.

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

    LIST FILES.
    
  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.

  4. LIST ListKeyword FROM SomeVessel IN YourVariable.

    This variant is just like variant (3), except that it gives a list of the items that exist on some other vessel that might not necessarily be the current CPU_vessel.

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
List of Celestial Bodies
Targets
List of possible target Vessels

Vessel Lists

These generate lists of items on the Vessel:

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

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 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
Volumes
List all the volumes that exist.

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 currently target vessel
LIST RESOURCES FROM TARGET IN foo.
FOR res IN foo {
    PRINT res:NAME. // Will print the name of every
                    // resource in the vessel
}.