SpaceCenter#

Provides functionality to interact with Kerbal Space Program. This includes controlling the active vessel, managing its resources, planning maneuver nodes and auto-piloting.

expansions: List#

The names of the installed expansions, for example "Serenity" (Breaking Ground) or "MakingHistory" (Making History).

Attribute:

Read-only, cannot be set

Return type:

List

science: number#

The current amount of science.

Attribute:

Read-only, cannot be set

Return type:

number

funds: number#

The current amount of funds.

Attribute:

Read-only, cannot be set

Return type:

number

reputation: number#

The current amount of reputation.

Attribute:

Read-only, cannot be set

Return type:

number

active_vessel: SpaceCenter.Vessel#

The currently active vessel.

Attribute:

Can be read or written

Return type:

SpaceCenter.Vessel or Types.none

vessels: List#

A list of all the vessels in the game.

Attribute:

Read-only, cannot be set

Return type:

List

launch_sites: List#

A list of available launch sites.

Attribute:

Read-only, cannot be set

Return type:

List

bodies: Map#

A dictionary of all celestial bodies (planets, moons, etc.) in the game, keyed by the name of the body.

Attribute:

Read-only, cannot be set

Return type:

Map

target_body: SpaceCenter.CelestialBody#

The currently targeted celestial body.

Attribute:

Can be read or written

Return type:

SpaceCenter.CelestialBody or Types.none

target_vessel: SpaceCenter.Vessel#

The currently targeted vessel.

Attribute:

Can be read or written

Return type:

SpaceCenter.Vessel or Types.none

target_docking_port: SpaceCenter.DockingPort#

The currently targeted docking port.

Attribute:

Can be read or written

Return type:

SpaceCenter.DockingPort or Types.none

static clear_target()#

Clears the current target.

static launchable_vessels(craft_directory)#

Returns a list of vessels from the given craft_directory that can be launched.

Parameters:

craft_directory (string) – Name of the directory in the current saves “Ships” directory. For example "VAB" or "SPH".

Return type:

List

static launch_vessel(craft_directory, name, launch_site[, crew = Types.none][, recover = true][, flag_url = ''])#

Launch a vessel.

Parameters:
  • craft_directory (string) – Name of the directory in the current saves “Ships” directory, that contains the craft file. For example "VAB" or "SPH".

  • name (string) – Name of the vessel to launch. This is the name of the “.craft” file in the save directory, without the “.craft” file extension.

  • launch_site (string) – Name of the launch site. For example "LaunchPad" or "Runway".

  • crew (List or Types.none) – The Kerbals to place in the craft, by name. Controls how the craft is crewed, as described in the remarks.

  • recover (boolean) – If true and there is a vessel on the launch site, recover it before launching.

  • flag_url (string) – If not nil, the asset URL of the mission flag to use for the launch.

Note

The crew parameter controls how the craft is crewed:

  • If nil, the craft’s default crew assignments are used.

  • If an empty list, the craft is launched with no crew.

  • Otherwise, the named Kerbals are placed in the craft in the order given: the first name takes the first seat, the second name the next seat, and so on, scanning the craft’s parts in order. No other Kerbals are hired to fill remaining seats. Throws an exception, without launching, if a name does not match an available Kerbal or the craft has too few seats for the requested crew.

Throws an exception if any of the games pre-flight checks fail.

static launch_vessel_from_vab(name[, recover = true])#

Launch a new vessel from the VAB onto the launchpad.

Parameters:
  • name (string) – Name of the vessel to launch.

  • recover (boolean) – If true and there is a vessel on the launch pad, recover it before launching.

Note

This is equivalent to calling SpaceCenter.launch_vessel() with the craft directory set to “VAB” and the launch site set to “LaunchPad”. Throws an exception if any of the games pre-flight checks fail.

static launch_vessel_from_sph(name[, recover = true])#

Launch a new vessel from the SPH onto the runway.

Parameters:
  • name (string) – Name of the vessel to launch.

  • recover (boolean) – If true and there is a vessel on the runway, recover it before launching.

Note

This is equivalent to calling SpaceCenter.launch_vessel() with the craft directory set to “SPH” and the launch site set to “Runway”. Throws an exception if any of the games pre-flight checks fail.

editor: SpaceCenter.Editor#

The editor, for inspecting the vessel that is being constructed.

Attribute:

Read-only, cannot be set

Return type:

SpaceCenter.Editor

static save(name)#

Save the game with a given name. This will create a save file called name.sfs in the folder of the current save game.

Parameters:

name (string) – Name of the save.

static load(name)#

Load the game with the given name. This will create a load a save file called name.sfs from the folder of the current save game.

Parameters:

name (string) – Name of the save.

static quicksave()#

Save a quicksave.

Note

This is the same as calling SpaceCenter.save() with the name “quicksave”.

static quickload()#

Load a quicksave.

Note

This is the same as calling SpaceCenter.load() with the name “quicksave”.

can_save: boolean#

Whether the game can be saved.

Attribute:

Read-only, cannot be set

Return type:

boolean

Note

The game cannot be saved in some flight states, e.g. while under acceleration or moving over the surface. Setting KRPC.game_scene to leave flight saves the game only when this is true.

static can_revert_to_launch()#

Whether the current flight can be reverted to launch.

Return type:

boolean

static revert_to_launch()#

Revert the current flight to launch.

static transfer_crew(crew_member, target_part)#

Transfers a crew member to a different part.

Parameters:
ui_visible: boolean#

Whether the UI is visible.

Attribute:

Can be read or written

Return type:

boolean

navball: boolean#

Whether the navball is visible.

Attribute:

Can be read or written

Return type:

boolean

altimeter_mode: SpaceCenter.AltimeterMode#

The current mode of the altimeter.

Attribute:

Can be read or written

Return type:

SpaceCenter.AltimeterMode

ut: number#

The current universal time in seconds.

Attribute:

Read-only, cannot be set

Return type:

number

g: number#

The value of the gravitational constant G in \(N(m/kg)^2\).

Attribute:

Read-only, cannot be set

Return type:

number

buoyancy_scalar: number#

The multiplier the game applies to every buoyant force.

Attribute:

Read-only, cannot be set

Return type:

number

Note

Stock KSP sets it to 1.2. A buoyant force is a fifth larger than Archimedes’ principle alone gives.

warp_rate: number#

The current warp rate. This is the rate at which time is passing for either on-rails or physical time warp. For example, a value of 10 means time is passing 10x faster than normal. Returns 1 if time warp is not active.

Attribute:

Read-only, cannot be set

Return type:

number

warp_factor: number#

The current warp factor. This is the index of the rate at which time is passing for either regular “on-rails” or physical time warp. Returns 0 if time warp is not active. When in on-rails time warp, this is equal to SpaceCenter.rails_warp_factor, and in physics time warp, this is equal to SpaceCenter.physics_warp_factor.

Attribute:

Read-only, cannot be set

Return type:

number

rails_warp_factor: number#

The time warp rate, using regular “on-rails” time warp. A value between 0 and 7 inclusive. 0 means no time warp. Returns 0 if physical time warp is active.

If requested time warp factor cannot be set, it will be set to the next lowest possible value. For example, if the vessel is too close to a planet. See the KSP wiki for details.

Attribute:

Can be read or written

Return type:

number

Note

Outside the flight scene, every factor can be set.

physics_warp_factor: number#

The physical time warp rate. A value between 0 and 3 inclusive. 0 means no time warp. Returns 0 if regular “on-rails” time warp is active.

Attribute:

Can be read or written

Return type:

number

static can_rails_warp_at([factor = 1])#

Returns True if regular “on-rails” time warp can be used, at the specified warp factor. The maximum time warp rate is limited by various things, including how close the active vessel is to a planet. See the KSP wiki for details.

Parameters:

factor (number) – The warp factor to check.

Return type:

boolean

Note

Outside the flight scene, every valid factor can be used.

maximum_rails_warp_factor: number#

The current maximum regular “on-rails” warp factor that can be set. A value between 0 and 7 inclusive. See the KSP wiki for details.

Attribute:

Read-only, cannot be set

Return type:

number

Note

Outside the flight scene, this is the highest factor.

static warp_to(ut[, max_rails_rate = 1e+05][, max_physics_rate = 2.0])#

Uses time acceleration to warp forward to a time in the future, specified by universal time ut. This call blocks until the desired time is reached. Uses regular “on-rails” or physical time warp as appropriate. For example, physical time warp is used when the active vessel is traveling through an atmosphere. When using regular “on-rails” time warp, the warp rate is limited by max_rails_rate, and when using physical time warp, the warp rate is limited by max_physics_rate.

Parameters:
  • ut (number) – The universal time to warp to, in seconds.

  • max_rails_rate (number) – The maximum warp rate in regular “on-rails” time warp.

  • max_physics_rate (number) – The maximum warp rate in physical time warp.

Returns:

When the time warp is complete.

Note

Outside the flight scene, only regular “on-rails” time warp is used. Throws an exception if the game scene changes during the time warp.

static transform_position(position, from, to)#

Converts a position from one reference frame to another.

Parameters:
Returns:

The corresponding position, as a vector, in reference frame to.

Return type:

Tuple

static transform_direction(direction, from, to)#

Converts a direction from one reference frame to another.

Parameters:
Returns:

The corresponding direction, as a vector, in reference frame to.

Return type:

Tuple

static transform_rotation(rotation, from, to)#

Converts a rotation from one reference frame to another.

Parameters:
  • rotation (Tuple) – Rotation, as a quaternion of the form \((x, y, z, w)\), in reference frame from.

  • from (SpaceCenter.ReferenceFrame) – The reference frame that the rotation is in.

  • to (SpaceCenter.ReferenceFrame) – The reference frame to covert the rotation to.

Returns:

The corresponding rotation, as a quaternion of the form \((x, y, z, w)\), in reference frame to.

Return type:

Tuple

static transform_velocity(position, velocity, from, to)#

Converts a velocity (acting at the specified position) from one reference frame to another. The position is required to take the relative angular velocity of the reference frames into account.

Parameters:
  • position (Tuple) – Position, as a vector, in reference frame from.

  • velocity (Tuple) – Velocity, as a vector that points in the direction of travel and whose magnitude is the speed in meters per second, in reference frame from.

  • from (SpaceCenter.ReferenceFrame) – The reference frame that the position and velocity are in.

  • to (SpaceCenter.ReferenceFrame) – The reference frame to covert the velocity to.

Returns:

The corresponding velocity, as a vector, in reference frame to.

Return type:

Tuple

static raycast_distance(position, direction, reference_frame)#

Cast a ray from a given position in a given direction, and return the distance to the hit point. If no hit occurs, returns infinity.

Parameters:
  • position (Tuple) – Position, as a vector, of the origin of the ray.

  • direction (Tuple) – Direction of the ray, as a unit vector.

  • reference_frame (SpaceCenter.ReferenceFrame) – The reference frame that the position and direction are in.

Returns:

The distance to the hit, in meters, or infinity if there was no hit.

Return type:

number

static raycast_part(position, direction, reference_frame)#

Cast a ray from a given position in a given direction, and return the part that it hits. If no hit occurs, returns nil.

Parameters:
  • position (Tuple) – Position, as a vector, of the origin of the ray.

  • direction (Tuple) – Direction of the ray, as a unit vector.

  • reference_frame (SpaceCenter.ReferenceFrame) – The reference frame that the position and direction are in.

Returns:

The part that was hit or nil if there was no hit.

Return type:

SpaceCenter.Part or Types.none

far_available: boolean#

Whether Ferram Aerospace Research is installed.

Attribute:

Read-only, cannot be set

Return type:

boolean

real_fuels_available: boolean#

Whether RealFuels is installed.

Attribute:

Read-only, cannot be set

Return type:

boolean

static create_kerbal(name, job, male)#

Creates a Kerbal.

Parameters:
  • name (string)

  • job (string)

  • male (boolean)

static get_kerbal(name)#

Find a Kerbal by name.

Parameters:

name (string)

Return type:

SpaceCenter.CrewMember or Types.none

map_filter: SpaceCenter.MapFilterType#

The visible objects in map mode.

Attribute:

Can be read or written

Return type:

SpaceCenter.MapFilterType

static screenshot(file_path[, scale = 1])#

Saves a screenshot.

Parameters:
  • file_path (string) – The path of the file to save.

  • scale (number) – Resolution scaling factor

game_mode: SpaceCenter.GameMode#

The current mode the game is in.

Attribute:

Read-only, cannot be set

Return type:

SpaceCenter.GameMode

warp_mode: SpaceCenter.WarpMode#

The current time warp mode. Returns SpaceCenter.WarpMode.none if time warp is not active, SpaceCenter.WarpMode.rails if regular “on-rails” time warp is active, or SpaceCenter.WarpMode.physics if physical time warp is active.

Attribute:

Read-only, cannot be set

Return type:

SpaceCenter.WarpMode

camera: SpaceCenter.Camera#

An object that can be used to control the camera.

Attribute:

Read-only, cannot be set

Return type:

SpaceCenter.Camera

waypoint_manager: SpaceCenter.WaypointManager#

The waypoint manager.

Attribute:

Read-only, cannot be set

Return type:

SpaceCenter.WaypointManager

contract_manager: SpaceCenter.ContractManager#

The contract manager.

Attribute:

Read-only, cannot be set

Return type:

SpaceCenter.ContractManager

alarm_manager: SpaceCenter.AlarmManager#

The alarm manager.

Attribute:

Read-only, cannot be set

Return type:

SpaceCenter.AlarmManager

class SpaceCenter.GameMode#

The game mode. Returned by SpaceCenter.GameMode

sandbox#

Sandbox mode.

career#

Career mode.

science#

Science career mode.

science_sandbox#

Science sandbox mode.

mission#

Mission mode.

mission_builder#

Mission builder mode.

scenario#

Scenario mode.

scenario_non_resumable#

Scenario mode that cannot be resumed.

class SpaceCenter.AltimeterMode#

The mode of the altitude reported on the altimeter. See SpaceCenter.altimeter_mode.

default#

The altimeter is in the default mode.

asl#

The altimeter is in the “Above Sea Level” mode.

agl#

The altimeter is in the “Above Ground Level” mode.

class SpaceCenter.WarpMode#

The time warp mode. Returned by SpaceCenter.WarpMode

rails#

Time warp is active, and in regular “on-rails” mode.

physics#

Time warp is active, and in physical time warp mode.

none#

Time warp is not active.

class SpaceCenter.MapFilterType#

The set of things that are visible in map mode. These may be combined with bitwise logic.

all#

Everything.

none#

Nothing.

debris#

Debris.

unknown#

Unknown.

space_objects#

SpaceObjects.

probes#

Probes.

rovers#

Rovers.

landers#

Landers.

ships#

Ships.

stations#

Stations.

bases#

Bases.

ev_as#

EVAs.

flags#

Flags.

plane#

Planes.

relay#

Relays.

site#

Launch Sites.

deployed_science_controller#

Deployed Science Controllers.

class SpaceCenter.LaunchSite#

A place where craft can be launched from. More of these can be added with mods like Kerbal Konstructs.

name: string#

The name of the launch site.

Return type:

string

body: SpaceCenter.CelestialBody#

The celestial body the launch site is on.

Return type:

SpaceCenter.CelestialBody

editor_facility: SpaceCenter.EditorFacility#

Which editor is normally used for this launch site.

Return type:

SpaceCenter.EditorFacility

class SpaceCenter.EditorFacility#

Editor facility. See SpaceCenter.LaunchSite.editor_facility.

vab#

Vehicle Assembly Building.

sph#

Space Plane Hanger.

none#

None.