Settings management
Currently, plugin settings are managed through TMInterface console variables. Saving arbitrary settings in other formats will be added in later versions.
A console variable is either a string
, bool
or double
type. To create a new console variable, use the RegisterVariable
function:
void Main() {
RegisterVariable("plugin_check", true); // registers a boolean variable with the default value being true
}
It is strongly recommended to register variables with a clear namespace e.g: pluginname_varname
.
Once registered, TMInterface will automatically track the variable and save its value to the builtin.txt
config file. Once the plugin
is enabled/launching at startup, calling RegisterVariable
will add the variable back with the same value it had when the game closed.
Once a variable has been registered, it is not possible to deregister it in the same game session.
Binding UI elements with variables
Whenever possible, TMInterface exposes convenient Var
functions to bind UI elements with console variables. For example, to bind a checkbox with a boolean variable, use the UI::CheckboxVar
function:
UI::CheckboxVar("Check", "plugin_check");
which replaces:
bool val = GetVariableBool("plugin_check");
UI::Checkbox("Check", val);
SetVariable("plugin_check", val);
The plugin_[name]_enabled
variable
Every plugin gets its own plugin_name_enabled
console variable automatically. This variable is used to track enabled state of the plugin.
The name
is a cleaned up version of the plugin file/folder name. To preview what is your plugin name, type set plugin_
in the console and find your plugin in the autocomplete list.
Toggling this variable with SetVariable
on your plugin or other plugins will actually enable/disable them.
Note that this is an implementation detail and is not guaranteed to work in future versions of TMInterface. In that case, it will be replaced with a real API call.