Revision Difference
Entity:SetNetworked2VarProxy#561490
<function name="SetNetworked2VarProxy" parent="Entity" type="classfunc">
<description>
Sets a function to be called when the NW2Var changes. Internally uses <page>GM:EntityNetworkedVarChanged</page> to call the function.
<note>Only one NW2VarProxy can be set per-var
Running this function clientside will only set it for the client it is called on.</note></description>
<realm>Shared</realm>
<file line="600-L611">lua/includes/extensions/entity.lua</file>
<args>
<arg name="name" type="string">The name of the NW2Var to add callback for.</arg>
<arg name="callback" type="function">The function to be called when the NW2Var changes. It has 4 arguments:⤶
* <page>Entity</page> ent - The entity⤶
* <page>string</page> name - Name of the NW2Var that has changed⤶
* <page>any</page> oldval - The old value⤶
* <page>any</page> newval - The new value</arg>
<arg name="callback" type="function">The function to be called when the NW2Var changes.⤶
⤶
<callback>⤶
<arg type="Entity" name="ent">The entity</arg>⤶
<arg type="string" name="name">Name of the NW2Var that has changed</arg>⤶
<arg type="any" name="oldval">The old value</arg>
<arg type="any" name="newval">The new value</arg>⤶
</callback>⤶
</arg>⤶
</args>
</function>
<example>
<description>Prints all changes to a NW2Var called "Key" of Player 1.</description>
<code>
Entity( 1 ):SetNetworked2VarProxy( "Key", print )
Entity( 1 ):SetNW2String( "Key", "Value" )
Entity( 1 ):SetNW2String( "Key", "Table" )
</code>
<output>
```
Player [1][Player1] Key nil Value
Player [1][Player1] Key Value Table
```
</output>
</example>