Skip to content
You're reading the docs for Railroader 0.6 (the MoW Update), currently available on the Experimental branch.

Commands

Registers slash commands in the in-game console. Reached via ui.registerCommand().

commandName string Command name; a leading / is added automatically if omitted
description string Shown alongside the command in /help output
callback (string[]) => string? Called with the command's arguments; its return value (if a string) is printed to the console

Registers a console command. Re-registering the same command name (case-insensitive) replaces the previous registration (a warning is logged) — including one registered by a different asset pack. Throws if callback isn’t a function, or if called outside an asset pack context.

ui.registerCommand("/hello", "Prints a greeting", (args) => {
if args.length > 0 {
return "Hello, \(args[0])!"
}
return "Hello!"
})

Typing /hello world in the console calls callback with ["world"] (the command name itself is not included) and prints Hello, world!.

  • Quoted substrings in console input are preserved as a single argument, e.g. /mycommand "hello world" calls callback with ["hello world"].
  • Returning a string from callback prints it to the console; returning anything else (including nothing) prints nothing.
  • Exceptions thrown by callback are caught and shown in the console as Error: <message> rather than crashing anything.
  • Commands can be invoked by an unambiguous unique prefix (e.g. /hel if no other command starts with hel); an ambiguous prefix lists the possible matches instead of running anything.
  • Built-in engine commands are matched before script commands, so a script command can’t override one of those — but it can override another asset pack’s script command of the same name.
  • There’s no method to unregister a command, and no way to declare a fixed argument count/schema — callback receives the raw argument strings and is responsible for parsing/validating them itself. Registrations don’t survive a map/session change; a command must be re-registered each time Main.rl runs.