cvars.AddChangeCallback
From GMod Wiki
Function | |
Syntax |
cvars.AddChangeCallback( String ConVar, Function Callback ) Where is this used? |
Description: | |
Registers a callback function to be called when the specified ConVar's value is changed. | |
Returns: | nil |
Part of Library: | cvars |
Realm: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=Cvars.AddChangeCallback]Cvars.AddChangeCallback [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Example
CreateConVar("my_cvar", "", FCVAR_NOTIFY) local function funcCallback(CVar, PreviousValue, NewValue) print(CVar.." changed from "..PreviousValue.." to "..NewValue.."!") end cvars.AddChangeCallback("my_cvar", funcCallback)
Notes
- These CVar change callbacks are not networked; server-side changes only register server-side. Only the table of the convar is sent in callback 'CVar', not the actual ConVar object. To fix, use GetConVar(CVar) in any situation where needed.
- Returning anything in the callback has no effect.
- For this to work for ConVars on the server, the ConVar must be created with the FCVAR_GAMEDLL flag.