S&box Wiki

Revision Difference

Network_Callbacks#560459

<cat>Code.Network</cat>⤶ <title>Network Callbacks</title>⤶ ⤶ You can get a notification when a `[Net]` property has changed **clientside**. This is useful if you want to update something in the UI, or run some other logic when the variable changes on the client without having to poll for changes frequently.⤶ ⤶ Simply add the `[Change]` attribute alongside your `[Net]` property, by default this calls On[PropertyName]Changed.⤶ ⤶ ```csharp⤶ [Net, Change] ⤶ public string DataString { get; set; }⤶ ⤶ public void OnDataStringChanged( string oldValue, string newValue )⤶ {⤶ Log.Info( $"changed from {oldValue} to {newValue}" );⤶ }⤶ ```⤶ ⤶ ```csharp⤶ [Net, Change( nameof( DoSomething ) )] ⤶ public string DataString { get; set; }⤶ ⤶ public void DoSomething( string oldValue, string newValue )⤶ {⤶ Log.Info( $"changed from {oldValue} to {newValue}" );⤶ }⤶ ```⤶