Garry's Mod Wiki

Entity:SetNW2VarProxy

  Entity:SetNW2VarProxy( string 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

You should not use the NW2 System on entities that are based on a Lua Entity, or else this will be called multiple times and the NW2Var could get mixed up with other ones.

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

Arguments

1 string 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