Skip to content

Creating Commands

George L. Albany edited this page Jan 17, 2018 · 1 revision

Commands

  1. Create a function that accepts OS and List as parameters (lambdas and delegates work as well)
  2. Register it via Pathfinder.Command.Handler.RegisterCommand where the values for the command are:
    1. key - the name of the command and what value will execute it in the game's terminal
    2. function - the function you plan to execute (it can be created here too) it returns whether it disconnects the user from the currently connected computer
    3. description - the help description of the command, defaults to null, if null (not just empty), it will be hidden from the help system
    4. autocomplete - determines whether the command will autocomplete in game, defaults to false

The method will return null if it failed, otherwise it returns the mod unique identifying command id

So:

Command.Handler.RegisterCommand("hello_cmd", (os, args) => { os.write("hello"); return false; }, "says hello", true);

will register a command that is called 'hello_cmd' that will say hello in the terminal, tells you that in the help system, and will autocomplete if it appears to be in the process of being typed.

You can also assign other methods with the same parameter order to this so:

bool HelloCmd(OS os, List<string> args) { os.write("hello"); return false; }
/* irrelevant stuff */
Command.Handler.RegisterCommand("hello_cmd", HelloCmd, "says hello", true);

which will do the exact same thing.

You can not yet write command functions of void type yet and thus; while they could be one line in the case your command connects or disconnects based on the expression's return, you likely don't want to do so and thus must write them in code blocks.

Also said command should not manipulate any data that isn't thread safe or messes with threading in any way as every command is executed on its own thread and thus in parallel.

Clone this wiki locally