KRPC#
- class KRPC#
Main kRPC service, used by clients to interact with basic server functionality.
- string GetClientName ()#
Returns the name of the current client. This is an empty string if the client has no name.
- Game Scenes:
All
- IList<ClientInfo> Clients { get; }#
The RPC clients that are currently connected to the server.
- Game Scenes:
All
- KRPC.Schema.KRPC.Status GetStatus ()#
Returns some information about the server, such as the version.
- Game Scenes:
All
- KRPC.Schema.KRPC.Services GetServices ()#
Returns information on all services, procedures, classes, properties etc. provided by the server. Can be used by client libraries to automatically create functionality such as stubs.
- Game Scenes:
All
- KRPC.Schema.KRPC.Stream AddFunctionStream (Expression function)#
Add a stream of the value a server side function computes on each update.
- Parameters:
- Game Scenes:
All
Note
Each call adds a new stream, with values of the type given by
Expression.ReturnType. Any exception from the function ends the stream, including one for an object that is not loaded. A procedure that pauses execution to resume on a later tick produces an error on the stream.
- void HoldTick ()#
Hold the game on its current physics tick until
KRPC.ReleaseTickis called or the hold times out. Every call made in between is executed before the game advances, so a read, compute and write all happen in the state of one tick.- Game Scenes:
All
Note
The game renders no frame, takes no input and runs no physics while the tick is held. Keep a hold as short as possible, and release it even when the code between the two calls fails.
A tick is held once, so this waits for the next tick when the current one has already been released. One client holds the tick at a time, and only a client making a call can hold it: a stream or an event cannot.
A hold ends by itself when it times out, when the client disconnects, and when the client calls a procedure that takes more than one tick to finish, such as staging or warping. Stream updates are sent once the tick is released, so waiting for a stream or an event inside a hold waits out the timeout.
- void ReleaseTick ()#
Let the game move on from the tick that
KRPC.HoldTickheld it on. Does nothing when no tick is held, which is the case once a hold has timed out.- Game Scenes:
All
- void NextTick ()#
Let the game move on from the tick being held and hold the one after it, so that a program acts on consecutive physics ticks. Holds the soonest tick it can if no tick is currently being held.
- Game Scenes:
All
Note
A release and a hold made as two separate calls let the game advance between them. This takes the next tick without that gap. Call it at the top of a loop that has to act on every tick, work, and come back to it.
The game advances one tick per call, so it runs at the rate of the loop for as long as the loop runs. End the loop with
KRPC.ReleaseTick.Every limit of
KRPC.HoldTickapplies, the timeout included. A hold lost to the timeout is not reported, and the next call takes whatever tick it lands on.
- void CompileFunction (Expression function)#
Compile a server side function, so that running, streaming or adding it as an event does not compile it.
- Parameters:
- Game Scenes:
All
Note
Compiling a large function takes time on the game’s main thread. Compiling it in advance keeps that time out of its first run.
- byte[] RunFunction (Expression function, IList<byte[]> arguments = null)#
Run a server side function once, within a single physics tick, and return the value it produces.
- Parameters:
function – The function to run.
arguments – The encoded arguments, one per parameter. If null, defaults to
new System.Collections.Generic.List<byte[]> { }.
- Returns:
The encoded value of the function, or no bytes for a function with no value.
- Game Scenes:
All
Note
The arguments are encoded at the types given by
Expression.ParameterTypes. Throws an exception if a procedure the function calls pauses execution, and the effects up to the pause remain.
- GameScene GameScene { get; set; }#
The current game scene. Setting this switches the game to the given scene, or opens/closes the corresponding facility for the pseudo-scenes. Scene changes happen asynchronously: setting this property returns immediately, and clients should poll it until it reports the requested scene. Setting it to
GameScene.Flightresumes the save’s active vessel, and fails if there is none. Moving betweenGameScene.EditorVABandGameScene.EditorSPHkeeps the vessel that is being constructed, as the game’s own switch editor button does. Leaving flight saves the game first, unless the game cannot be saved, e.g. while under acceleration.- Game Scenes:
All
- enum GameScene#
The game scene. See
KRPC.GameScene.- SpaceCenter#
The game scene showing the Kerbal Space Center buildings.
- Flight#
The game scene showing a vessel in flight (or on the launchpad/runway).
- TrackingStation#
The tracking station.
- EditorVAB#
The Vehicle Assembly Building.
- EditorSPH#
The Space Plane Hangar.
- MissionBuilder#
The mission builder.
- AstronautComplex#
The astronaut complex. This is a pseudo-scene, shown when the astronaut complex facility is open within the space center scene.
- MissionControl#
Mission control. This is a pseudo-scene, shown when the mission control facility is open within the space center scene.
- ResearchAndDevelopment#
Research and development. This is a pseudo-scene, shown when the research and development facility is open within the space center scene.
- Administration#
The administration facility. This is a pseudo-scene, shown when the administration facility is open within the space center scene.
- struct ClientInfo#
A client connected to the server.
Note
See
KRPC.Clients.
- class InvalidOperationException#
A method call was made to a method that is invalid given the current state of the object.
- class ArgumentException#
A method was invoked where at least one of the passed arguments does not meet the parameter specification of the method.
- class ArgumentNullException#
A null reference was passed to a method that does not accept it as a valid argument.
- class ArgumentOutOfRangeException#
The value of an argument is outside the allowable range of values as defined by the invoked method.
- class NullReferenceException#
A value was null where its type does not allow one.
- class KeyNotFoundException#
A key was not found in a dictionary.
- class IndexOutOfRangeException#
An index was outside the bounds of a collection, string or array.
- class DivideByZeroException#
An integer was divided by zero.
- class NotSupportedException#
A method was invoked that is not supported.
- class TimeoutException#
An operation did not complete in the time allotted to it.
- class OverflowException#
An arithmetic or conversion operation overflowed.
- class ObjectDestroyedException#
The game object that a service object refers to no longer exists, so the object cannot be used. For example, the part it represents was destroyed, or the vessel it belongs to was recovered.
- class ObjectNotLoadedException#
The game object that a service object refers to exists, but is not loaded. For example, the game is loading, or the vessel carrying the part is unloaded.
- class UnsupportedSceneException#
The procedure is not available in the current game scene.
- class StreamRemovedException#
A stream was removed by the server, e.g. an event that has finished.
- class Error#
A general error, described by its message.