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));
}
Registering a Simple Block Command
Many commands do one thing to every block of a type that matches a name, group or tag. Use RegisterBlockCommand<T>() from BaseModule instead of writing a command class for each one. This also keeps your script smaller.
public override void Boot()
{
RegisterBlockCommand<IMyDoor>("door/open", door => door.OpenDoor(), "Door opened: {0}");
RegisterBlockCommand<IMyDoor>("door/close", door => door.CloseDoor(), "Door closed: {0}");
}
| Parameter | Description |
|---|---|
name | The command name, for example door/open. |
action | Applied to each matching block. |
message | Format string for the success response. {0} is the block name. |
Use a command class with RegisterCommand() when your command needs several arguments, options or custom validation.
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
Built-in Commands
| Command | Description |
|---|---|
halt | Halts the script by clearing every queued delayed task and active coroutine on the Clock. Pending wait delays and parallel commands that have not run yet are cleared. |
Options With Spaces
Options accept double-quoted values, so a value can contain spaces. Read it with GetOption().
view/go "Cockpit:1" MainMenu --title="Custom Title"
string title = command.GetOption("title"); // Custom Title
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.
