Click or drag to resize
Commands Class
Commands is used for all things regarding commands. Mainly, you can register your own commands and help messages here.
Inheritance Hierarchy
SystemObject
  spaar.ModLoaderCommands

Namespace: spaar.ModLoader
Assembly: SpaarModLoader (in SpaarModLoader.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public static class Commands

The Commands type exposes the following members.

Properties
  NameDescription
Public propertyStatic memberHistory
List of all executed commands. This returns a read-only list.
Top
Methods
  NameDescription
Public methodStatic memberDoesCommandExist
Checks whether a command currently exists (is registered).
Public methodStatic memberHandleCommand
Handle an entered command. Arguments are parsed and then the callback corresponding to the command is called.
Public methodStatic memberRegisterCommand
Register a console command. The passed callback will be called when the user enters the command in the console. If the same command was previously registered by the same mod, the old one will be updated instead of a new one being registered.
Public methodStatic memberRegisterHelpMessage
Register a help message for your mod to be displayed with the 'help' command. This should give a general overview, to give specific information about a command, use the helpText parameter of RegisterCommand.
Top
Remarks
Commands can be entered in the console by the user. The command can be entered by itself if it is only registered once, if multiple mods registered the same command they are differentiated by entering <modname>:<command>. Commands can take two types of arguments: named arguments and unnamed arguments. Unnamed arguments are simply values entered on the console after the command, seperated by spaces. Named arguments follow this format: --name value.
Examples
Commands.RegisterCommand("myCommand", MyCallback);
An example implementation of the callback might looks like this:
private string MyCallback(string[] args,
IDictionary<string, string> namedArgs)
{
  if (args.Length != 2)
  {
    return "Usage: myCommand <param1> <param2>";
  }
  return "You passed " + args[0] + " and " + args[1];
}
Of course it is also possible to implement the callback as a lambda or anonymous delegate instead of a full function:
Commands.RegisterCommand("myCommand", (args, namedArgs) =>
{
  if (args.Length != 2)
  {
    return "Usage: myCommand <param1> <param2>";
  }
  return "You passed " + args[0] + " and " + args[1];
});
Registers a new command called myCommand. This can then be used like this:
myCommand arg1 "second unnamed arg" --namedArg1 value1 --namedArg2 "second value"
If called as above, args passed to the callback will contain ["arg1", "second unnamed arg"] NamedArgs will contain the following mappings: "namedArg1" -> "value1", "namedArg2" -> "second value".
See Also