Command Bus
CommandBus registers commands from core modules, extension modules, and programmable block Custom Data, then resolves and executes them as local commands, routines, or construct-wide delegated commands.
Registering a Command
Commands are usually registered in a module's Boot() method.
public override void Boot()
{
RegisterCommand(new SetLightColorCommand(this));
}
Running a Command or Routine
RunTerminalCommand() accepts the same routine syntax the player uses in the programmable block terminal.
GetModule<CommandBus>().RunTerminalCommand(
"light/color \"Dock Light\" yellow; wait 2; light/color \"Dock Light\" green"
);
That means you can trigger:
- Single commands.
- Multi-step routines.
- Config commands defined in
[commands]. - Construct-wide commands exported by other Mother instances.
Config Commands
Programmable block Custom Data commands are loaded by Configuration, then executed by CommandBus.
[commands]
prepareDock=light/color "Dock Light" yellow; wait 1; connector/lock "Dock Connector"
prepareDock
Construct-Wide Command Sharing
Mother Core shares command names with other Mother instances on the same construct. If another script exposes a command and your script does not, CommandBus can delegate to that remote instance automatically.
[commands]
greeting=screen/print MainDisplay "Hello, Space Engineer!";
greeting
Important Commands and Force-Local Execution
Prefix a config command with ! to mark it as construct-priority.
[commands]
!alert=light/color "Warning Lights" red; sound/play "Alarm"
If another script needs to bypass the important construct command and run its own local definition, prefix the call with !!.
!!alert
Helpful Members
| Member | Use |
|---|---|
ModuleCommands | Commands registered on this instance |
ConstructCommands | Command names discovered on other scripts on the same construct |
ImportantConstructCommands | Important command names exported by other scripts |
FindInstanceWithCommand(name) | Returns the script ID that owns a construct command |
GetSelfCommandNames() | Returns the local command names exported to peers |
Emitted Events
CommandBus does not emit any built-in events.
