Docs / Plugins / Writing plugins
Settings
omsi.plugin.settings declares the plugin's settings and returns the values the player chose:
local settings = omsi.plugin.settings({
{ key = "send", type = "bool", label = "Send the values to a program", default = false },
{ key = "port", type = "number", label = "UDP port", default = 47800, min = 1024, max = 65535, step = 1 },
{ key = "unit", type = "choice", label = "Speed in", choices = { "km/h", "mph" }, default = "km/h" },
{ key = "name", type = "text", label = "Your name", default = "" },
}, "Telemetry HUD")
omsi.on("setting", function(key, value)
settings[key] = value
end)| Field | Meaning |
|---|---|
key |
the setting's name (required, unique) |
type |
"bool", "number", "text" or "choice" |
label |
the text shown; default the key |
default |
the value before the player changes it |
min, max, step |
for number; defaults 0, 100, 0 (any) |
choices |
for choice: a list of texts (required) |
The second argument is the title; the default is the plugin's name. A plugin can declare up to 40 settings. Values are kept in range: a number is clamped and rounded to step, a choice must be one of choices.
The player can change settings in two places:
- In the game:
omsi.plugin.show_settings()opens a panel with checkboxes, sliders, text fields and tabs. It can be dragged and closed while the panels have the mouse. - In the launcher: Plugins → Installed → Settings. The launcher reads
settings.schema.jsonand writessettings.jsonin the plugin's data folder. The plugin gets the values the next time it starts.
Every change in the game sends the setting(key, value) event. omsi.plugin.setting(key) reads one value, omsi.plugin.set_setting(key, value) changes one.
Something wrong or missing? Fix it on GitHub or open an issue.