Skip to content

Action handlers

MOARdV edited this page Jan 1, 2018 · 40 revisions

Action handlers are plugins for JSIActionGroupSwitch, allowing you to tie in-IVA animated switches provided by this module to foreign execution code. There isn't that much need for this feature externally, but internally RasterPropMonitor components use it to tie interface plugins into the framework.

The plugin mode is enabled by giving 'plugin' as the action name:

actionName = plugin

When this is present, the PLUGINACTION blocks in the module configuration are parsed. Multiple blocks will be parsed, until one loads successfully:

	PLUGINACTION
	{
		name = MechJebRPMButtons
		actionMethod = ButtonRetrograde
		stateMethod = ButtonRetrogradeState
	}
  • name -- is the name of the module to load.
  • actionMethod -- The name of the method to call on the module when button state changes. (public void ActionMethod(bool buttonState))
  • stateMethod -- The name of the method to call on the module to determine which state the button is actually in. (public bool StateMethod()) This parameter is optional, if it is not present, JSIActionGroupSwitch will track the button state itself.
  • stateVariable -- As an alternative to 'stateMethod', you can tie the switch's state to a different variable. This variable can be a CUSTOM_ variable or any other variable that functions like a Boolean (true/false) variable, such as BRAKES, SAS, etc.

If no block resulted in a successful module instance, the switch will be treated as if the action name was dummy.

To create your own action handler, you need to know these things:

  • The handler must be an InternalModule. Only one copy will be created per prop if multiple instances of JSIActionGroupSwitch are present in it, and it must survive calls by multiple copies.
  • The actionMethod is a void method that takes one bool parameter -- true if the switch is to be turned on, and false if the switch is to be turned off.
  • The stateMethod is a method that takes no parameters and returns a bool value -- true if the switch is currently in the 'on' state and false if it's in the off state. If this method is not provided, JSIActionGroupSwitch will keep track of the current state of the switch itself -- use it if the state of your action cannot change independently of the switch.

Builtin action handlers

JSIFAR

This module, JSIFAR, provides access to Ferram Aerospace Research information and controls.

JSIInternalRPMButtons

This module is part of the core RPM DLL. It provides access to some functionality that can be implemented without using external plugins.

  • ButtonActivateReserves/ButtonActivateReservesState -- Turns on all resources that were disabled by the player (for instance, by right-clicking on a monopropellant tank, and clicking on the small icon next to the tank's capacity to prevent it from being used). The button is 'on' when there is at least one resource whose flow was disabled.
  • ButtonClearNodes/ButtonClearNodesState -- Clears all maneuver nodes on the current vessel. The button is 'on' when there is at least one valid maneuver node.
  • ButtonClearTarget/ButtonClearTargetState -- Clears the current target. The button is 'on' when there is a valid target.
  • ButtonEnableElectricGenerator/ButtonEnableElectricGeneratorState -- Turns on all electrical generators (ModuleGenerator or ModuleResourceConverters that produce ElectricCharge). The button state returns 1 when at least one such generator is active.
  • ButtonPrecisionMode/ButtonPrecisionModeState -- Sets / clears precision input mode.
  • ButtonSpeedMode/ButtonSpeedModeState -- Toggles the speed mode between orbital, surface, and target. The button is 'on' at all times.
  • ButtonStageLock/ButtonStageLockState -- Toggles stage locking (preventing staging), the same as alt-L. The button is 'on' when staging is locked, and off otherwise.
  • ButtonSASModeStabilityAssist/ButtonSASModeStabilityAssistState -- Enables SAS Stability Assist mode.
  • ButtonSASModePrograde/ButtonSASModeProgradeState -- Enables SAS Prograde mode.
  • ButtonSASModeRetrograde/ButtonSASModeRetrogradeState -- Enables SAS Retrograde mode.
  • ButtonSASModeNormal/ButtonSASModeNormalState -- Enables SAS Normal mode.
  • ButtonSASModeAntiNormal/ButtonSASModeAntiNormalState -- Enables SAS AntiNormal mode.
  • ButtonSASModeRadialIn/ButtonSASModeRadialInState -- Enables SAS RadialIn mode.
  • ButtonSASModeRadialOut/ButtonSASModeRadialOutState -- Enables SAS RadialOut mode.
  • ButtonSASModeTarget/ButtonSASModeTargetState -- Enables SAS Target mode.
  • ButtonSASModeAntiTarget/ButtonSASModeAntiTargetState -- Enables SAS AntiTarget mode.
  • ButtonSASModeManeuver/ButtonSASModeManeuverState -- Enables SAS Maneuver mode.
  • GetSASMode/SetSASMode -- For use with JSINumericInput and transfer JSIActionGroupSwitch modules, these methods allow getting and setting the SAS mode using a numeric value: StabilityAssist = 0, Prograde = 1, Retrograde = 2, Normal = 3, Antinormal = 4, RadialIn = 5, RadialOut = 6, Target = 7, AntiTarget = 8, Maneuver = 9. Some modes may not work (for instance, Maneuver does nothing if there's no maneuver node). at least one active gimbal is locked.
  • RadarEnable/RadarEnableState -- Enables/Disables all JSIRadar modules on the craft; returns true when any radar is enabled.
  • RecoverVessel/CanRecoverVessel -- Recovers a vessel when it is recoverable (landed on Kerbin); returns true when the vessel may be recovered.
  • TrimNeutralState -- Returns true if all three trim settings are less than 1% (between -1% and +1%).
  • SetAllTrimNeutral, SetPitchTrimNeutral, SetRollTrimNeutral, SetYawTrimNeutral -- Neutralize all trim settings, or each axis individually.
  • SetPitchTrim, SetRollTrim, SetYawTrim -- Set the corresponding axis's trim to the desired percentage (from -100 to +100 - values outside of that range are clamped).
  • SetDeploySolarPanels/GetDeploySolarPanels -- Used to deploy and retract deployable solar panels.
  • SolarPanelsDeployable/SolarPanelsRetractable -- Returns 1 when there is at least one solar panel that may be deployed or retracted, respectively.
  • SolarPanelState -- Returns a number representing the current state of deployable solar panels. If different types of deployable solar panels are installed that deploy at different speeds, or if different panels are kept at different deployment states, this value may not accurate. Returns -1 if no deployable solar panels are found, 0 for 'retracted', 1 for 'extended', 2 for 'retracting', 3 for 'extending', and 4 for 'broken'. These values are taken directly from KSP's numeric table.

Docking control

RPM can control a docking port using these callback methods, with some limitations. Since only one docking port can be controlled at a time with these callbacks, RPM will select a docking port that is the current reference transformation (if the current reference has a docking port). Otherwise, it will select the first docking port that belongs to the same vessel as the current IVA. In other words, once you dock to a space station, RPM will not let you control one of the space station's docking ports (unless you select it as the reference transform). if you have multiple docking ports on your craft, RPM will select the first one it finds in the parts list (which may or may not be the same each time - if you have multiple docking ports, you should be selecting a reference part before using these methods).

  • DockUndock / DockDetach -- Undocks the spacecraft (in the first method) or detaches the object attached to the docking port's node (in the second method), provided the parameter being passed is "false".
  • DockAttached / DockDocked / DockReady -- Returns '1' if there is an object pre-attached to the dock (something that was attached in the VAB), if there is a craft docked to the dock, or if the dock is ready for docking, respectively.

Engine Control

  • ButtonCutThrottle/ButtonCutThrottleState -- Cuts the throttle (sets it to 0%). The button state returns '1' when the throttle is already at or below 1%.
  • ButtonEnableEngines/ButtonEnableEnginesState -- Turns on all engines on the current stage, the same as right-clicking each engine and selecting "Activate". When engines are on, the button turns off all engines on any stage that have been activated and can be turned off (SRBs, for instance, are not affected).
  • ButtonFullThrottle/ButtonFullThrottleState -- Sets the throttle to full (100%). The button state returns 1 when the throttle is already at or above 99%.
  • GimbalLock/GimbalLockState -- Turns on/off gimbals on all of the active engines. The state method is 'on' when the gimbal is locked.
  • SetEnginesPrimaryMode/GetEnginesPrimaryMode -- Used to toggle multi-mode engines, and determine whether any active engines are operating in primary mode (if no MME engines are active, it will return true).
  • SetThrottleLimit -- Used to set the throttle limit slider on the engines. Valid numbers range 0 - 100.
  • SetThrustReverser/GetThrustReverserEnabled -- Reports status of and allows changes to animations registered with JSIThrustReverser Part Modules.

Wheel / Landing Gear State

  • LandingGearState -- Similar to SolarPanelState, but reporting the state of retractable landing gear.
  • LandingGearPosition -- provides a numeric value between 0 and 1 describing the current position of the landing gear, with 0 being retracted and 1 being extended.
  • GetWheelsDamaged -- Returns 1 if any wheels are currently damaged.
  • GetWheelsRepairable -- Returns 1 if any wheels may be repaired (not that they need repaired, just that someone can repair them if they need it).
  • GetWheelStress -- Returns the stress value of the most stressed wheel on the vessel (ranging from 0 to 100?).
  • GetWheelBrakes/SetWheelBrakes -- Returns and changes the brake force tweakable for the wheels on the vessel.

JSIKAC

RasterPropMonitor is able to interact with the Kerbal Alarm Clock mod to provide some basic information from that mod. The following methods are available.

  • ActiveVesselAlarms -- Provides a count of all of the alarms assigned to the current vessel (including past alarms that have not been deleted).
  • NextAlarmName -- Provides the short name of the next alarm, or an empty string if there are no alarms assigned to the current vessel.
  • NextAlarmTime -- Provides the time (seconds) until the next alarm assigned to the current vessel will fire, or zero if there are no future alarms.
  • NextAlarmType -- Provides the type (as a string) of the next alarm, or an empty string if there are no alarms assigned to the current vessel.

JSIParachute

This module provides control over parachutes, allowing them to be deployed or cut. If the user has RealChute Parachute Systems installed, JSIParachute can deploy or cut those parachutes as well as arm or disarm them.

CutParachute is separate from DeployParachutes to prevent accidents if the Deploy button is pressed twice. CutParachute only works if it's called with a 'false' parameter, so it should be paired with DeployParachutesState as the stateMethod of a JSIActionGroupSwitch (so it won't do anything unless a parachute has been deployed).

  • ArmParachutes/ArmParachutesState -- Arms all RealChute parachutes. When RealChute is not installed it toggles an internal variable (so an "armed" indicator light will switch on). The state is '1' when at least one parachute is armed (or, absent RealChute, when the internal variable is set).
  • CutParachutes -- Cuts all deployed parachutes.
  • DeployParachutes / DeployParachutesState -- Deploys all parachutes. The state is '1' when any parachutes are deployed.

JSIPilotAssistant

The JSIPilotAssistant module interacts with the Pilot Assistant mod, providing a way to control Pilot Assistant's auto-pilots from IVA props.

JSIMechJeb (MechJebRPMButtons)

This module provides access to SmartASS and other functions with pairs of actionMethod/stateMethod. The proper module name is "JSIMechJeb"; however, the legacy "MechJebRPMButtons" works as well.

Variables marked DEPRECATED work with MechJeb released version 2.6.1 and earlier, as well as MechJeb dev builds #741 or earlier. Due to changes in the MechJeb space plane autopilots, these features will not work with later versions of MechJeb.

  • ButtonAscentGuidance/ButtonAscentGuidanceState -- Ascent autopilot button. Pressing this button will turn ascent autopilot on. The button is in the 'on' state while the ascent autopilot is active.
  • ButtonEnableLandingPrediction/ButtonEnableLandingPredictionState -- Enables the MechJeb Landing Guidance prediction system. This system estimates where the vessel will land, and how far from its target that landing will be. When Land at Target is enabled, this function is automatically engaged. The button state is on when the prediction system is on. To get a better idea why you might want to use this, take a look at MechJebRPMVariable.
  • ButtonForceRoll/ButtonForceRollState -- Enable the SmartASS Force Roll button. The button state is on when Force Roll is active.
  • ButtonForceRoll0/ButtonForceRoll0State -- Enables Force Roll, and sets the orientation to 0. The button state is on when Force Roll is engaged, and the roll is set to 0.
  • ButtonForceRoll90/ButtonForceRoll90State -- Enables Force Roll, and sets the orientation to +90. The button state is on when Force Roll is engaged, and the roll is set to +90.
  • ButtonForceRoll180/ButtonForceRoll180State -- Enables Force Roll, and sets the orientation to 180. The button state is on when Force Roll is engaged, and the roll is set to 180.
  • ButtonForceRoll270/ButtonForceRoll270State -- Enables Force Roll, and sets the orientation to -90. The button state is on when Force Roll is engaged, and the roll is set to -90.
  • ButtonHorizontalPlus/ButtonHorizontalPlusState -- HVEL+
  • ButtonHorizontalMinus/ButtonHorizontalMinusState -- HVEL-
  • ButtonKillRot/ButtonKillRotState -- KILL ROT
  • ButtonLandingGuidance/ButtonLandingGuidanceState -- Engage the MechJeb Landing Guidance pilot. If a valid ground target is targeted, this button acts as "Land at Target". Otherwise, this button acts as "Land Somewhere". The button is in the 'on' state when the landing pilot is enabled.
  • ButtonNode/ButtonNodeState -- NODE
  • ButtonNodeExecute/ButtonNodeExecuteState -- Node execution button. Pressing this button will execute the next maneuver node if one exists. The button is in the 'on' state while the node is being executed.
  • ButtonNormalMinus/ButtonNormalMinusState -- NML-
  • ButtonNormalPlus/ButtonNormalPlusState -- NML+
  • ButtonOff/ButtonOffState -- OFF
  • ButtonParMinus/ButtonParMinusState -- PAR-
  • ButtonParPlus/ButtonParPlusState -- PAR+
  • ButtonPlotHohmannTransfer/ButtonPlotHohmannTransferState -- Plot a Hohmann transfer orbit and create a maneuver node for it to the selected target (either a target in the same SoI, or another planet when orbiting a planet). The button is in the 'on' state (and functional) when a valid target is selected, and the ship is not in a highly elliptical orbit, and neither ship nor target are in hyperbolic orbits.
  • ButtonPrograde/ButtonProgradeState -- PROGRADE
  • ButtonRadialMinus/ButtonRadialMinusState -- RAD-
  • ButtonRadialPlus/ButtonRadialPlusState -- RAD+
  • ButtonRendezvousAutopilot/ButtonRendezvousAutopilotState -- Engages the Rendezvous Autopilot. The ship must be targeting a docking port for this mode to activate. The button is "on" when the autopilot is engaged.
  • ButtonRetrograde/ButtonRetrogradeState -- RETROGRADE
  • ButtonRvelMinus/ButtonRvelMinusState -- RVEL-
  • ButtonRvelPlus/ButtonRvelPlusState -- RVEL+
  • ButtonSpaceplaneAutoland/ButtonSpaceplaneAutolandState -- Engages the spaceplane autopilot "Autoland" mode, and returns whether the SP AP is currently in "Autoland" mode.
  • DEPRECATED ButtonSpaceplaneHoldHeading/ButtonSpaceplaneHoldHeadingState -- Engages the spaceplane autopilot "Hold Altitude and Heading" mode, and returns whether the SP AP is currently in "Hold" mode.
  • ButtonSurfacePrograde/ButtonSurfaceProgradeState -- Surface velocity prograde
  • ButtonSurfaceRetrograde/ButtonSurfaceRetrogradeState -- Surface velocity retrograde
  • ButtonTargetMinus/ButtonTargetMinusState -- TGT-
  • ButtonTargetPlus/ButtonTargetPlusState -- TGT+
  • ButtonVerticalPlus/ButtonVerticalPlus -- UP
  • DEPRECATED SpaceplaneAltitudeProximity -- Returns '1'/true if the spaceplane if within +/- 500 meters of the hold altitude.

JSIActionGroupSwitch transfer getter methods

The following methods are available to transfer values into a PERISTENT_ variable, or to use directly via a PLUGIN_ variable:

  • GetDeltaV, GetStageDeltaV -- Returns the remaining dV and current stage dV. Used internally for DELTAV and STAGEDELTAV.
  • GetForceRollAngle -- Returns the current value of the Force Roll Smart ASS setting.
  • GetLandingAltitude -- Returns the height above sea level / datum for the estimated point of landing.
  • GetLandingError -- Returns the estimated error between a selected landing point and the estimated point of landing.
  • GetLandingLatitude, GetLandingLongitude -- Reports the estimated lat/lon of the point of landing. Valid only when Landing Prediction is enabled.
  • GetLandingTime -- Reports the seconds until landing. Valid only when Landing Prediction is enabled.
  • GetLaunchAltitude -- Returns the Ascent Autopilot target orbit altitude.
  • GetLaunchInclination -- Get the currently stored inclination for the ascent autopilot.
  • GetTerminalVelocity -- Returns the terminal velocity for the current altitude (used internally for the TERMINALVELOCITY variable).
  • DEPRECATED SpaceplaneHoldAltitude, SpaceplaneHoldHeading, SpaceplaneGlideslope -- returns the currently-configured spaceplane autopilot's hold altitude, hold heading, and glideslope, respectively (use PLUGIN_JSIMechJeb:SpaceplaneHoldAltitude, etc, to read the values).

JSIActionGroupSwitch transfer setter methods

The following methods are available to transfer values from a PERSISTENT_ variable into MechJeb:

  • CircularizeAtAltitude -- Uses the persistent variable as the altitude for a "Circularize at Altitude" command. This method also creates the maneuver node for the next time the orbit crosses that altitude. It has no effect if the altitude is above the current apoapsis, or it is below the current periapsis.
  • ChangeApoapsis and ChangePeriapsis -- Uses the persistent variable as the new desired Ap or Pe. It also creates the maneuver node to change the apsis (scheduled on the opposing apsis - so a ChangeApoapsis is scheduled at the next periapsis). Has no effect when invalid parameters are used (like setting Ap below Pe, or Pe above Ap).
  • SetLaunchAltitude, SetLaunchInclination -- Configure the ascent autopilot's altitude and inclination.
  • DEPRECATED SetSpaceplaneHoldAltitude, SetSpaceplaneHoldHeading, SetSpaceplaneGlideslope -- Uses the persistent variable to set the hold altitude, hold heading, and glideslope, respectively.