Settings

Hooks

swatch_config_setting_changed

Called whenever a setting has changed.

Arguments

  1. (String) settingKey

  2. (Any) value

  3. (Any) oldValue

Example

hook.Add("swatch_config_setting_changed", "onsettingchanged", function(key, value, oldValue)
    sWatch.log("d", string.format("Setting %q changed from %q to %q", key, tostring(oldValue), tostring(value)))
end)

Functions

sWatch.setSetting

Can be used to change a setting or create a new one. Als see lua\swatch\modules\config\defaultsettings.lua on how to use this function. This is a bit messed up.

Arguments

  1. (String) key - Name like modulename_whateveryouwant

  2. (Any) value - Can be string, number or table

  3. (Boolean) showInUI (optional) - true to display in admin menu

  4. (Boolean) ifNotExists (optional) - true to only create/change if setting does not exist

  5. (Table) options (optional) - All allowed values

  6. (Boolean) advancedSetting (optional) - true to only show when advanced mode is enbaled in admin menu

Returns

  1. (Any) newValue - nil if function failed

Example

Create new setting that is visible inside admin menu

sWatch.setSetting(
    "networking_concommand_logging", // key
    true, // value
    true, // show in UI
    true, // only if it does not already exist
    nil, // all values accepted
    true // it is a advanced setting
)

Create new setting that stores internal values

sWatch.setSetting(
    "server_maps", 
    {"gm_construct", "gm_anything"}, // store a table in the setting
    false, // don't show in admin menu
    true // only if setting does not exist
)

Change above setting

sWatch.setSetting("server_maps", {"another_map"})
sWatch.getSetting

Arguments

  1. (String) key

  2. (Any) defaultValue - will get returned if setting does not exist

Returns

  1. (Any) setting - the setting you requested or defaultValue

Example

Get value of a setting

local val = sWatch.getSetting("modulename_any_setting", "nothing")

Check if a setting exist and create if not

local secret = sWatch.getSetting("devicecookie_serverSecret", false)
if cookieServerSecret == false then
    cookieServerSecret = sWatch.setSetting("devicecookie_serverSecret", sWatch.generateString(32))
end
sWatch.getSettingDescription

Returns the corresponding description of your setting from the language file.

Arguments

  1. (String) key

Returns

  1. (String) description

sWatch.getAllSettings

Returns

  1. (Table) allSettings

sWatch.getOptions

Arguments

  1. (String) key

Returns

  1. (Table) avaliableOptions - {} if setting has no options, nil if setting does not exist

Last updated