Skip to content

Settings, input, and console ​

Define settings and register input actions when your mod initialises. The game's Options menu displays supported settings and keybindings. Settings API reference

Define a typed setting ​

Add a setting to the first mod to control how much information a diagnostic command prints.

csharp
using StellarWorks.Configuration;

// In OnInitializeMelon.
var verbose = mod.Configuration.Define("verbose", false, new SettingOptions<bool>
{
    DisplayName = mod.Localization.Text("verbose", "Verbose diagnostics"),
    Category = "Diagnostics",
    Scope = SettingScope.ClientLocal
});

Read verbose.Value in your code or call verbose.Set(value) for a writable setting. Subscribe to mod.Configuration.Changed to respond to accepted edits. Use World for a setting that must travel with the save, Server for host installation settings, and Startup when a value only takes effect after restarting. Server and world settings are available in an authoritative world.

Add a command and shortcut ​

Register a uniquely named command and use the same diagnostic from a rebindable keyboard action.

csharp
using StellarWorks.Input;

// In OnInitializeMelon, after defining verbose.
void PrintStatus()
{
    mod.Console.WriteLine(verbose.Value
        ? $"Mod {mod.Id}. World is {mod.World.Current?.State.ToString() ?? "closed"}."
        : "First mod is loaded.");
}

mod.Console.RegisterCommand("firstmod-status", "Prints the current mod status.", _ => PrintStatus());

var status = mod.Input.RegisterAction("show_status", new InputActionDefinition(
    "Show first-mod status", KeyChord.Parse("Ctrl+Shift+F8"))
{
    Contexts = InputContext.Gameplay
});
status.Pressed.Subscribe("print_status", _ => PrintStatus());

Press backtick to open or close the StellarWorks console. Enter help for the command list. Tab completes commands and Up or Down recalls past entries. Use the Keybindings menu to change the shortcut.

Translate labels ​

Use mod.Localization.Text(key, fallback) for settings and action labels. Add a JSON object in Localization/en.json in the mod's assets for English, for example:

json
{
  "verbose": "Verbose diagnostics"
}

With embedded assets, give that file the logical resource name StellarWorks.Assets/Localization/en.json. Supply additional files such as Localization/fr.json for other locales. For content names and descriptions, assign NameKey and DescriptionKey on definitions, or use PartBuilder.WithLocalization on a part. The display name and description provide fallbacks.

StellarWorks documentation · Mods for StellarDrive