-
Notifications
You must be signed in to change notification settings - Fork 18
Creating Commands
- Create a function that accepts OS and List as parameters (lambdas and delegates work as well)
- Register it via
Pathfinder.Command.Handler.RegisterCommand
where the values for the command are:- key - the name of the command and what value will execute it in the game's terminal
- 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
- description - the help description of the command, defaults to null, if null (not just empty), it will be hidden from the help system
- 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.