Garry's Mod Wiki

Revision Difference

cvars.AddChangeCallback#514262

<function name="AddChangeCallback" parent="cvars" type="libraryfunc">⤶ <description>⤶ Adds a callback to be called when the named convar changes.⤶ ⤶ <bug issue="1440">This does not callback convars in the menu state.</bug>⤶ <bug issue="3503">This does not callback convars on the client with FCVAR_GAMEDLL and convars on the server without FCVAR_GAMEDLL.</bug>⤶ <bug issue="3740">This does not callback convars on the client with FCVAR_REPLICATED.</bug>⤶ </description>⤶ <realm>Shared and Menu</realm>⤶ <args>⤶ <arg name="name" type="string">The name of the convar to add the change callback to.</arg>⤶ <arg name="callback" type="function">The function to be called when the convar changes. The arguments passed are:&#xA;* &lt;page&gt;string&lt;/page&gt; convar - The name of the convar.&#xA;* &lt;page&gt;string&lt;/page&gt; oldValue - The old value of the convar.&#xA;* &lt;page&gt;string&lt;/page&gt; newValue - The new value of the convar.</arg>⤶ <arg name="identifier" type="string" default="nil">If set, you will be able to remove the callback using &lt;page&gt;cvars.RemoveChangeCallback&lt;/page&gt;.</arg>⤶ </args>⤶ </function>⤶ ⤶ <example>⤶ <description>Called when convar changes.</description>⤶ <code>⤶ cvars.AddChangeCallback("convar name", function(convar_name, value_old, value_new)⤶ print(convar_name, value_old, value_new)⤶ end)⤶ </code>⤶ <output>"convar name" 2 5</output>⤶ ⤶ </example>