Service#
Provides functionality to interact with Kerbal Space Program. This includes controlling the active vessel, managing its resources, planning maneuver nodes and auto-piloting.
- SpaceCenter.getExpansions()#
The names of the installed expansions, for example
"Serenity"(Breaking Ground) or"MakingHistory"(Making History).- Property:
Read-only, cannot be set
- Return type:
Arrayofstring
- SpaceCenter.getScience()#
The current amount of science.
- Property:
Read-only, cannot be set
- Return type:
number
- SpaceCenter.getFunds()#
The current amount of funds.
- Property:
Read-only, cannot be set
- Return type:
number
- SpaceCenter.getReputation()#
The current amount of reputation.
- Property:
Read-only, cannot be set
- Return type:
number
- SpaceCenter.getActiveVessel()#
- SpaceCenter.setActiveVessel(value)#
The currently active vessel.
- Property:
Can be read or written
- Return type:
SpaceCenter.Vesselornull
- SpaceCenter.getVessels()#
A list of all the vessels in the game.
- Property:
Read-only, cannot be set
- Return type:
ArrayofSpaceCenter.Vessel
- SpaceCenter.getLaunchSites()#
A list of available launch sites.
- Property:
Read-only, cannot be set
- Return type:
ArrayofSpaceCenter.LaunchSite
- SpaceCenter.getBodies()#
A dictionary of all celestial bodies (planets, moons, etc.) in the game, keyed by the name of the body.
- Property:
Read-only, cannot be set
- Return type:
MapfromstringtoSpaceCenter.CelestialBody
- SpaceCenter.getTargetBody()#
- SpaceCenter.setTargetBody(value)#
The currently targeted celestial body.
- Property:
Can be read or written
- Return type:
SpaceCenter.CelestialBodyornull- Game Scenes:
Flight
- SpaceCenter.getTargetVessel()#
- SpaceCenter.setTargetVessel(value)#
The currently targeted vessel.
- Property:
Can be read or written
- Return type:
SpaceCenter.Vesselornull- Game Scenes:
Flight
- SpaceCenter.getTargetDockingPort()#
- SpaceCenter.setTargetDockingPort(value)#
The currently targeted docking port.
- Property:
Can be read or written
- Return type:
SpaceCenter.DockingPortornull- Game Scenes:
Flight
- SpaceCenter.clearTarget()#
Clears the current target.
- Game Scenes:
Flight
- SpaceCenter.launchableVessels(craftDirectory)#
Returns a list of vessels from the given craftDirectory that can be launched.
- Arguments:
craftDirectory (
string) – Name of the directory in the current saves “Ships” directory. For example"VAB"or"SPH".
- Return type:
Arrayofstring
- SpaceCenter.launchVessel(craftDirectory, name, launchSite[, crew[, recover[, flagUrl]]])#
Launch a vessel.
- Arguments:
craftDirectory (
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.launchSite (
string) – Name of the launch site. For example"LaunchPad"or"Runway".crew (
Arrayofstringornull) – 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. Defaults totrue.flagUrl (
string) – If notnull, the asset URL of the mission flag to use for the launch. Defaults to"".
Note
The crew parameter controls how the craft is crewed:
If
null, 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.
- SpaceCenter.launchVesselFromVAB(name[, recover])#
Launch a new vessel from the VAB onto the launchpad.
- Arguments:
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. Defaults totrue.
Note
This is equivalent to calling
SpaceCenter.launchVessel()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.
- SpaceCenter.launchVesselFromSPH(name[, recover])#
Launch a new vessel from the SPH onto the runway.
- Arguments:
name (
string) – Name of the vessel to launch.recover (
boolean) – If true and there is a vessel on the runway, recover it before launching. Defaults totrue.
Note
This is equivalent to calling
SpaceCenter.launchVessel()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.
- SpaceCenter.getEditor()#
The editor, for inspecting the vessel that is being constructed.
- Property:
Read-only, cannot be set
- Return type:
- Game Scenes:
Editor Vab, Editor Sph
- SpaceCenter.save(name)#
Save the game with a given name. This will create a save file called
name.sfsin the folder of the current save game.- Arguments:
name (
string) – Name of the save.
- SpaceCenter.load(name)#
Load the game with the given name. This will create a load a save file called
name.sfsfrom the folder of the current save game.- Arguments:
name (
string) – Name of the save.
- SpaceCenter.quicksave()#
Save a quicksave.
Note
This is the same as calling
SpaceCenter.save()with the name “quicksave”.
- SpaceCenter.quickload()#
Load a quicksave.
Note
This is the same as calling
SpaceCenter.load()with the name “quicksave”.
- SpaceCenter.getCanSave()#
Whether the game can be saved.
- Property:
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.getGameScene()to leave flight saves the game only when this is true.
- SpaceCenter.canRevertToLaunch()#
Whether the current flight can be reverted to launch.
- Return type:
boolean
- SpaceCenter.revertToLaunch()#
Revert the current flight to launch.
- SpaceCenter.transferCrew(crewMember, targetPart)#
Transfers a crew member to a different part.
- Arguments:
crewMember (
SpaceCenter.CrewMember) – The crew member to transfer.targetPart (
SpaceCenter.Part) – The part to move them to.
- Game Scenes:
Flight
- SpaceCenter.getUIVisible()#
- SpaceCenter.setUIVisible(value)#
Whether the UI is visible.
- Property:
Can be read or written
- Return type:
boolean- Game Scenes:
Flight
Whether the navball is visible.
- Property:
Can be read or written
- Return type:
boolean- Game Scenes:
Flight
- SpaceCenter.getAltimeterMode()#
- SpaceCenter.setAltimeterMode(value)#
The current mode of the altimeter.
- Property:
Can be read or written
- Return type:
- Game Scenes:
Flight
- SpaceCenter.getUT()#
The current universal time in seconds.
- Property:
Read-only, cannot be set
- Return type:
number
- SpaceCenter.getG()#
The value of the gravitational constant G in \(\mathrm{N(m/kg)^{2}}\).
- Property:
Read-only, cannot be set
- Return type:
number
- SpaceCenter.getBuoyancyScalar()#
The multiplier the game applies to every buoyant force.
- Property:
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.
- SpaceCenter.getWarpRate()#
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.
- Property:
Read-only, cannot be set
- Return type:
number- Game Scenes:
Space Center, Flight, Tracking Station
- SpaceCenter.getWarpFactor()#
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.getRailsWarpFactor(), and in physics time warp, this is equal toSpaceCenter.getPhysicsWarpFactor().- Property:
Read-only, cannot be set
- Return type:
number- Game Scenes:
Space Center, Flight, Tracking Station
- SpaceCenter.getRailsWarpFactor()#
- SpaceCenter.setRailsWarpFactor(value)#
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.
- Property:
Can be read or written
- Return type:
number- Game Scenes:
Space Center, Flight, Tracking Station
Note
Outside the flight scene, every factor can be set.
- SpaceCenter.getPhysicsWarpFactor()#
- SpaceCenter.setPhysicsWarpFactor(value)#
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.
- Property:
Can be read or written
- Return type:
number- Game Scenes:
Flight
- SpaceCenter.canRailsWarpAt([factor])#
Returns
trueif 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.- Arguments:
factor (
number) – The warp factor to check. Defaults to1.
- Return type:
boolean- Game Scenes:
Space Center, Flight, Tracking Station
Note
Outside the flight scene, every valid factor can be used.
- SpaceCenter.getMaximumRailsWarpFactor()#
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.
- Property:
Read-only, cannot be set
- Return type:
number- Game Scenes:
Space Center, Flight, Tracking Station
Note
Outside the flight scene, this is the highest factor.
- SpaceCenter.warpTo(ut[, maxRailsRate[, maxPhysicsRate]])#
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 maxRailsRate, and when using physical time warp, the warp rate is limited by maxPhysicsRate.
- Arguments:
ut (
number) – The universal time to warp to, in seconds.maxRailsRate (
number) – The maximum warp rate in regular “on-rails” time warp. Defaults to1e+05.maxPhysicsRate (
number) – The maximum warp rate in physical time warp. Defaults to2.0.
- Game Scenes:
Space Center, Flight, Tracking Station
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.
- SpaceCenter.transformPosition(position, from, to)#
Converts a position from one reference frame to another.
- Arguments:
position (
[number, number, number]) – Position, as a vector, in reference frame from.from (
SpaceCenter.ReferenceFrame) – The reference frame that the position is in.to (
SpaceCenter.ReferenceFrame) – The reference frame to covert the position to.
- Returns:
The corresponding position, as a vector, in reference frame to.
- Return type:
[number, number, number]
- SpaceCenter.transformDirection(direction, from, to)#
Converts a direction from one reference frame to another.
- Arguments:
direction (
[number, number, number]) – Direction, as a vector, in reference frame from.from (
SpaceCenter.ReferenceFrame) – The reference frame that the direction is in.to (
SpaceCenter.ReferenceFrame) – The reference frame to covert the direction to.
- Returns:
The corresponding direction, as a vector, in reference frame to.
- Return type:
[number, number, number]
- SpaceCenter.transformRotation(rotation, from, to)#
Converts a rotation from one reference frame to another.
- Arguments:
rotation (
[number, number, number, number]) – 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:
[number, number, number, number]
- SpaceCenter.transformVelocity(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.
- Arguments:
position (
[number, number, number]) – Position, as a vector, in reference frame from.velocity (
[number, number, number]) – Velocity, as a vector that points in the direction of travel and whose magnitude is the speed in \(\mathrm{m/s}\), 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:
[number, number, number]
- SpaceCenter.raycastDistance(position, direction, referenceFrame)#
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.
- Arguments:
position (
[number, number, number]) – Position, as a vector, of the origin of the ray.direction (
[number, number, number]) – Direction of the ray, as a unit vector.referenceFrame (
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
- SpaceCenter.raycastPart(position, direction, referenceFrame)#
Cast a ray from a given position in a given direction, and return the part that it hits. If no hit occurs, returns
null.- Arguments:
position (
[number, number, number]) – Position, as a vector, of the origin of the ray.direction (
[number, number, number]) – Direction of the ray, as a unit vector.referenceFrame (
SpaceCenter.ReferenceFrame) – The reference frame that the position and direction are in.
- Returns:
The part that was hit or
nullif there was no hit.- Return type:
SpaceCenter.Partornull- Game Scenes:
Flight
- SpaceCenter.getFARAvailable()#
Whether Ferram Aerospace Research is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getAGExtAvailable()#
Whether Action Groups Extended is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getRealFuelsAvailable()#
Whether RealFuels is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getRealChuteAvailable()#
Whether RealChute is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getProceduralFairingsAvailable()#
Whether Procedural Fairings is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getNearFutureSolarAvailable()#
Whether Near Future Solar is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getDMagicAvailable()#
Whether DMagic’s DMModuleScienceAnimateGeneric is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getFirespitterAvailable()#
Whether Firespitter is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getKerbalActuatorsAvailable()#
Whether KerbalActuators is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getKSPCommunityPartModulesAvailable()#
Whether KSPCommunityPartModules is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getKOSAvailable()#
Whether kOS is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getB9PartSwitchAvailable()#
Whether B9PartSwitch is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getTweakScaleRescaledAvailable()#
Whether TweakScale Rescaled is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getRealAntennasAvailable()#
Whether RealAntennas is installed.
- Property:
Read-only, cannot be set
- Return type:
boolean
- SpaceCenter.getKerbals()#
The Kerbals in the roster.
- Property:
Read-only, cannot be set
- Return type:
ArrayofSpaceCenter.CrewMember
- SpaceCenter.createKerbal(name, job, male)#
Creates a Kerbal.
- Arguments:
name (
string)job (
string)male (
boolean)
- SpaceCenter.getKerbal(name)#
Find a Kerbal by name.
- Arguments:
name (
string)
- Return type:
SpaceCenter.CrewMemberornull
- SpaceCenter.getMapFilter()#
- SpaceCenter.setMapFilter(value)#
The visible objects in map mode.
- Property:
Can be read or written
- Return type:
- SpaceCenter.screenshot(filePath[, scale])#
Saves a screenshot.
- Arguments:
filePath (
string) – The path of the file to save.scale (
number) – Resolution scaling factor Defaults to1.
- Game Scenes:
Flight
- SpaceCenter.getGameMode()#
The current mode the game is in.
- Property:
Read-only, cannot be set
- Return type:
- SpaceCenter.getWarpMode()#
The current time warp mode. Returns
SpaceCenter.WarpMode.noneif time warp is not active,SpaceCenter.WarpMode.railsif regular “on-rails” time warp is active, orSpaceCenter.WarpMode.physicsif physical time warp is active.- Property:
Read-only, cannot be set
- Return type:
- Game Scenes:
Space Center, Flight, Tracking Station
- SpaceCenter.getCamera()#
An object that can be used to control the camera.
- Property:
Read-only, cannot be set
- Return type:
- Game Scenes:
Flight
- SpaceCenter.getWaypointManager()#
The waypoint manager.
- Property:
Read-only, cannot be set
- Return type:
- Game Scenes:
Flight
- SpaceCenter.getContractManager()#
The contract manager.
- Property:
Read-only, cannot be set
- Return type:
- Game Scenes:
Space Center, Flight, Tracking Station, Editor Vab, Editor Sph
- SpaceCenter.getAlarmManager()#
The alarm manager.
- Property:
Read-only, cannot be set
- Return type:
- class SpaceCenter.GameMode()#
The game mode. Returned by
SpaceCenter.GameMode- GameMode.sandbox#
Sandbox mode.
- GameMode.career#
Career mode.
- GameMode.science#
Science career mode.
- GameMode.scienceSandbox#
Science sandbox mode.
- GameMode.mission#
Mission mode.
- GameMode.missionBuilder#
Mission builder mode.
- GameMode.scenario#
Scenario mode.
- GameMode.scenarioNonResumable#
Scenario mode that cannot be resumed.
- class SpaceCenter.AltimeterMode()#
The mode of the altitude reported on the altimeter. See
SpaceCenter.getAltimeterMode().- AltimeterMode.default#
The altimeter is in the default mode.
- AltimeterMode.asl#
The altimeter is in the “Above Sea Level” mode.
- AltimeterMode.agl#
The altimeter is in the “Above Ground Level” mode.
- class SpaceCenter.WarpMode()#
The time warp mode. Returned by
SpaceCenter.WarpMode- WarpMode.rails#
Time warp is active, and in regular “on-rails” mode.
- WarpMode.physics#
Time warp is active, and in physical time warp mode.
- WarpMode.none#
Time warp is not active.
- class SpaceCenter.MapFilterType()#
The set of things that are visible in map mode.
Note
The values may be combined. A flags enumeration. Flags Enumerations shows how to combine its values.
- MapFilterType.all#
Everything.
- MapFilterType.none#
Nothing.
- MapFilterType.debris#
Debris.
- MapFilterType.unknown#
Unknown.
- MapFilterType.spaceObjects#
SpaceObjects.
- MapFilterType.probes#
Probes.
- MapFilterType.rovers#
Rovers.
- MapFilterType.landers#
Landers.
- MapFilterType.ships#
Ships.
- MapFilterType.stations#
Stations.
- MapFilterType.bases#
Bases.
- MapFilterType.evas#
EVAs.
- MapFilterType.flags#
Flags.
- MapFilterType.plane#
Planes.
- MapFilterType.relay#
Relays.
- MapFilterType.site#
Launch Sites.
- MapFilterType.deployedScienceController#
Deployed Science Controllers.
- class SpaceCenter.LaunchSite(fields)#
A place where craft can be launched from. More of these can be added with mods like Kerbal Konstructs.
- LaunchSite.name#
The name of the launch site.
- Type:
string
- LaunchSite.body#
The celestial body the launch site is on.
- LaunchSite.editorFacility#
Which editor is normally used for this launch site.
- LaunchSite.latitude#
The latitude of the point vessels launch from, in degrees, or
NaNif the site has no spawn point.- Type:
number
- LaunchSite.longitude#
The longitude of the point vessels launch from, in degrees, or
NaNif the site has no spawn point.- Type:
number
- LaunchSite.altitude#
The altitude above sea level of the point vessels launch from, in meters, or
NaNif the site has no spawn point.- Type:
number
- class SpaceCenter.EditorFacility()#
Editor facility. See
SpaceCenter.LaunchSite.editorFacility.- EditorFacility.vab#
Vehicle Assembly Building.
- EditorFacility.sph#
Space Plane Hanger.
- EditorFacility.none#
None.