config library
Defines the global config library, the framework's saved and networked configuration keys.
The server declares a key and its default with config.Add, and config.Get(key) returns an object with Get,
Set, GetNumber, GetDefault and similar methods. Changed values are saved per schema or globally, shared keys
are sent to clients over the Config message, and the client lists keys in the config system menu with
config.AddToSystem.
Summary
Functions
$key$ in a text with the value of that config key.Config Cable message.Functions
config.Add(key, value, isShared, isGlobal, isStatic, isPrivate, needsRestart)
shared gamemodes/catwork/gamemode/core/libraries/sh_config.lua:552On the server
Adds a new config key with a default value.
Values saved in the global or schema config files are applied to the new key, and shared keys are sent to every player. The key's category is the name of the plugin being loaded, if any. Does nothing when the key already exists or the value is not a string, number or boolean.
config.Add('default_attribute_points', 30, true)
config.Add('mysql_host', '', nil, nil, true, true, true)
Parameters
- key String Unique name of the key
- value Any Default value; a string, number or boolean
- isShared Boolean optional, defaults to
nilNetwork the value to clients - isGlobal Boolean optional, defaults to
nilSave the value for every schema instead of the current one - isStatic Boolean optional, defaults to
nilPrevent the value from changing unless forced - isPrivate Boolean optional, defaults to
nilMark the key as private - needsRestart Boolean optional, defaults to
nilApply changes only after a restart
Returns
- Config The new config object, or
nilwhen the key was not added
On the client
Adds a config key on the client, usually when the server sends its value.
Does nothing when the key already exists or the value is not a string, number or boolean.
Parameters
- key String Name of the key
- value Any Value of the key, also used as its default
Returns
- Config The new config object, or
nilwhen the key was not added
Defined in
config.AddToSystem(name, key, help, minimum, maximum, decimals, category)
client gamemodes/catwork/gamemode/core/libraries/sh_config.lua:761Adds a config key to the client's config system menu.
The category argument is ignored: it is always replaced by the name of the plugin being loaded,
falling back to 'Clockwork'.
Parameters
- name String Display name; the key when
nil - key String The config key
- help String Help text;
'#ConfigNoHelp'whennil - minimum Number optional, defaults to
0Minimum value for numeric keys - maximum Number optional, defaults to
100Maximum value for numeric keys - decimals Number optional, defaults to
0Number of decimals for numeric keys - category String optional, defaults to
nilUnused
Returns the config object for a key.
Objects for existing keys are cached. An object is returned even for keys that do not exist, so
check it with CLASS_TABLE:IsValid when the key might be missing.
local walkSpeed = config.Get('walk_speed'):GetNumber(100)
Parameters
- key String The config key
Returns
- Config The config object
Returns a config key's entry in the config system menu.
Parameters
- key String The config key
Returns
- Map The entry with
name,help,minimum,maximum,decimalsandcategory, ornil
Returns the table of every config entry, indexed by key.
Returns
- Map Config entries indexed by key, each with
value,defaultand flag fields
Returns the current value of a config key without creating a config object.
Parameters
- key String The config key
- failSafe Any optional, defaults to
nilValue returned when the key does not exist
Returns
- Any The current value, or
failSafe
See also
Returns whether the config has been initialized.
Returns
- Boolean Whether
config.SetInitializedhas been called withtrue
Returns whether the client has told the server that its config has initialized.
Returns
- Boolean Whether the
ConfigInitializedmessage was sent
Imports config keys from a text file and adds or updates them.
Each line has the form <class> <key> = <value>;, where the class contains any of boolean,
number, force, global, shared, static, private and restart to set the type and
flags. Lines starting with // and [section] lines are skipped. Existing keys are set, with
force bypassing the static flag; new keys are added with config.Add.
shared number default_attribute_points = 30;
Parameters
- fileName String Path of the file, relative to the
GAMEmount
Returns whether a value can be stored in a config key.
Parameters
- value Any The value to check
Returns
- Boolean Whether the value is a string, number or boolean
config.Load(fileName, loadGlobal)
server gamemodes/catwork/gamemode/core/libraries/sh_config.lua:489Loads saved config values from a data file, or applies every saved config file when no file is given.
Without a file name, the default and current map config files are read into config.global or
config.schema and applied to existing keys whose saved default matches their current default,
map values only applying on that map.
Parameters
- fileName String optional, defaults to
nilName of the data file to read and return - loadGlobal Boolean optional, defaults to
nilUse the framework's data folder instead of the schema's
Returns
- Map The saved entries when
fileNameis given; nothing otherwise
config.LoadINI(fileName, bFromGame, bStripQuotes)
shared gamemodes/catwork/gamemode/core/libraries/sh_config.lua:256Reads an INI file into a table of sections.
Comments starting with ; or # are stripped. Numeric and true/false values are converted.
Parameters
- fileName String Path of the file
- bFromGame Boolean optional, defaults to
nilRead from theGAMEmount instead ofDATA - bStripQuotes Boolean optional, defaults to
nilRemove double quotes from every line
Returns
- Map Sections indexed by name, each a
Mapof keys to values;falsewhen a line appears before the first section or a section header is not closed,nilwhen the file cannot be read
Replaces every $key$ in a text with the value of that config key.
Unknown keys are left in the text as they are.
config.Parse('Players start with $default_cash$ tokens.')
Parameters
- text String The text to parse
Returns
- String The text with the config values filled in
config.Save(fileName, configTable)
server gamemodes/catwork/gamemode/core/libraries/sh_config.lua:395Saves the config entries that differ from their defaults.
Global keys are saved with cw.core:SaveClockworkData and schema keys with
cw.core:SaveSchemaData. Map-specific, temporary and mysql_ keys are skipped, and a pending
nextValue is saved in place of the current value. When configTable is nil, both saved files
are deleted instead.
Parameters
- fileName String Name of the data file, e.g.
'config'or'config/gm_construct' - configTable Map optional, defaults to
nilConfig entries indexed by key, as returned byconfig.GetStored
Sends shared config values to players over the Config Cable message.
Only keys added as shared are sent. Bots are marked as config initialized straight away and fire
PlayerConfigInitialized instead of being sent anything.
Parameters
- player Player optional, defaults to
nilThe player to send to; every player whennil - key String optional, defaults to
nilThe key to send; every shared key whennil
config.SetInitialized(bInitalized)
shared gamemodes/catwork/gamemode/core/libraries/sh_config.lua:161Sets whether the config has been initialized.
On the server, config changes are only saved and ClockworkConfigChanged is only fired once this is
set; on the client it is set when the first Config message arrives from the server.
Parameters
- bInitalized Boolean Whether the config has initialized
config.SetSentInitialized(sentInitialized)
client gamemodes/catwork/gamemode/core/libraries/sh_config.lua:740Sets whether the client has told the server that its config has initialized.
Parameters
- sentInitialized Boolean Whether the
ConfigInitializedmessage was sent