Garry's Mod Wiki

Entity:SetNW2VarProxy

  Entity:SetNW2VarProxy( any key, function callback )

Description

Sets a function to be called when the NW2Var changes. Internally uses GM:EntityNetworkedVarChanged to call the function.
Alias of Entity:SetNetworked2VarProxy

Only one NW2VarProxy can be set per-var
Running this function will only set it for the realm it is called on.

Arguments

1 any key
The key of the NW2Var to add callback for.
2 function callback
The function to be called when the NW2Var changes. It has 4 arguments:

  • Entity ent - The entity
  • string name - Name of the NW2Var that has changed
  • any oldval - The old value
  • any newval - The new value

Example

Prints all changes to a NW2Var called "Key" of Player 1.

Entity( 1 ):SetNW2VarProxy( "Key", print ) Entity( 1 ):SetNW2String( "Key", "Value" ) Entity( 1 ):SetNW2String( "Key", "Table" )
Output:
Player [1][Player1] Key nil Value Player [1][Player1] Key Value Table