ConsoleCommands
The developer console is a text box the player opens with F1 to type commands. ConsoleCommands lets your mod add commands to it, print text into it and open it.
ConsoleCommands the developer console
This is the class you start from. Register adds a command to the console, Print writes a line into it, and Open opens it, as F1 does.
public static class ConsoleCommands
{
public static bool IsAvailable { get; }
public static bool IsOpen { get; }
public static bool Register(string modId, string name, string help, Action<string[]> run);
public static bool Print(string text);
public static bool Open();
}
| Method | Returns | What it does |
|---|---|---|
Register(modId, name, help, run) | bool | Adds a command to the developer console. true when added. |
Print(text) | bool | Writes a line into the console. true when written. |
Open() | bool | Opens the console, as F1 does. true when opened. |
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | true when the framework has set up the console and can add commands. |
IsOpen | bool | true while the console is open. |
Things to know
Registeradds a command. The name is one word, with no spaces or quotes.runis your code, and it gets the words the player typed after the command name. A quoted phrase counts as one word, as the game splits them.helpis the line that the console lists underMod commands:, after the game’s own list of commands.Printwrites a line to the console. Use it from inside your command to show output.Openopens the console, as F1 does. While the console is open the game does not count achievements. The player closes it with F1, or with the Pause Menu key while it is open. (The game ignores achievement triggers while the console is open. It setsAchievements.globalDisableon open and clears it on close.)IsOpenistruewhile the console is open.- The console is available in every build of the game. The F1 key always works.
OpenandPrintgive backfalseonly when the console is missing. (The game’s managed code has noisDebugBuildorUNITY_EDITORcheck on the console.)
Limits
Registergives backfalsewhenIsAvailableisfalse, when the name is already a game command, or when another mod added the name first. In the last two cases one warning in the log names both sides, and the first one keeps the name. If the same mod adds its own name again, it just getsfalse, with no warning. (The game has 52 command names of its own.IsAvailableisfalseuntil the framework has installed its console changes, so register from a plugin that starts after the framework.)Printgives backfalsewhen the console is not in the scene.Opengives backfalsewhen the console, or the achievement system, is not in the scene.