Skip to content

Working with Settings

Lynn edited this page Jun 1, 2019 · 1 revision

Setting up a new setting

Redmew supports setting and saving settings. For self-hosted solutions without server, this is stored per game. When playing on a Redmew hosted game it will be synced to the server and thus to other Redmew games running.

To add a custom setting you have to require the utility that lets you get and set them:

local Settings = require 'utils.redmew_settings'

Once you have this imported, you can register your custom settings:

local Settings = require 'utils.redmew_settings'

-- example
local name = 'toast-volume' -- this name will be how you call get(), set() and unset()
local type = Settings.types.fraction -- defines the storage type, fraction is between 0 and 1
local default = 1.0 -- the default value when a player hasn't set this before
local localisation_key = 'toast.toast_volume_setting_label' -- used for translations
Settings.register(name, setting_type, default, localisation_key)

By registering the setting you can now use get(), set() and unset() to control the value.

Modifying settings

-- get the setting
Settings.get(player.index, 'toast-volume')

-- set it
Settings.set(player.index, 'toast-volume', 0.5)

-- remove it for this player and fall back to the default
Settings.unset(player.index, 'toast-volume')

When a setting is changed, an event is fired; Settings.events.on_setting_set and contains data that can be used to update things in the scenario. Current usage examples:

  • When a setting updates outside of the settings GUI, it will also update the value in this GUI to reflect the current state
  • When a setting changes (regardless of where), the setting synchronization to the server will try to save it on the remote server

Managing settings

By default the scenario provides GUI to modify settings and will include things like error messages if input is invalid. You can add custom types in resources/setting_types.lua.

Clone this wiki locally