LethalNetworkAPI.LNetworkVariable<TData> Class
A variable that can be used to send data between clients.
public class LNetworkVariable<TData> : LethalNetworkAPI.Internal.LNetworkVariableBase
Type Parameters
Type | Description |
---|---|
TData | The type of data to send. |
Inheritance
↳ System.Object
↳ LNetworkVariableBase
↳ LNetworkVariable<TData>
Remarks
The type should not be mutable, otherwise you will have to manually use MakeDirty() upon modification (e.g. add, remove) of the mutable value.
Properties
OfflineValue
The "default" value of the variable. This value will be used when starting a new game.
Declaration
public TData OfflineValue { get; set; }
Value
The current value of the variable.
Declaration
public TData Value { get; set; }
Remarks
This value cannot be modified when disconnected. To change the "default" value, use OfflineValue.
Methods
Connect(string, TData, LNetworkVariableWritePerms, Action<TData,TData>)
Create a new LNetworkVariable<TData> if it doesn't already exist, otherwise return the existing variable of the same identifier.
Declaration
public static LNetworkVariable<TData> Connect(string identifier, TData offlineValue = default!, LNetworkVariableWritePerms writePerms = LNetworkVariableWritePerms.Server, Action<TData, TData>? onValueChanged = null)
Parameters
Type | Name | Description |
---|---|---|
string | identifier | The identifier of the LNetworkVariable<TData>. |
TData | offlineValue | [Opt.] The default value of the LNetworkVariable<TData>. This value will be used when starting a new game. |
LNetworkVariableWritePerms | writePerms | [Opt.] Who can modify the value of the LNetworkVariable<TData>. Defaults to . Will be ignored if the variable is already created. |
Action<TData, TData>? | onValueChanged | [Opt.] The method to run when the value of the LNetworkVariable<TData> changes. |
Returns
Type | Description |
---|---|
LNetworkVariable<TData> | The LNetworkVariable<TData>. |
Remarks
If you set the 'writePerms' to LNetworkVariableWritePerms.Owner, only the owner of the variable can modify it. See UpdateOwner(int[]) to update ownership.
Create(string, TData, LNetworkVariableWritePerms, Action<TData,TData>)
Create a new LNetworkVariable<TData> if it doesn't already exist. If it already exists, an exception will be thrown.
Declaration
public static LNetworkVariable<TData> Create(string identifier, TData offlineValue = default!, LNetworkVariableWritePerms writePerms = LNetworkVariableWritePerms.Server, Action<TData, TData>? onValueChanged = null)
Parameters
Type | Name | Description |
---|---|---|
string | identifier | The identifier of the LNetworkVariable<TData>. |
TData | offlineValue | [Opt.] The default value of the LNetworkVariable<TData>. This value will be used when starting a new game. |
LNetworkVariableWritePerms | writePerms | [Opt.] Who can modify the value of the LNetworkVariable<TData>. Defaults to . Will be ignored if the variable is already created. |
Action<TData, TData>? | onValueChanged | [Opt.] The method to run when the value of the LNetworkVariable<TData> changes. |
Returns
Type | Description |
---|---|
LNetworkVariable<TData> | The LNetworkVariable<TData>. |
Exceptions
Type | Description |
---|---|
InvalidOperationException | Thrown if the LNetworkVariable<TData> already exists. |
Remarks
If you set the 'writePerms' to LNetworkVariableWritePerms.Owner, only the owner of the variable can modify it. See UpdateOwner(int[]) to update ownership.
Dispose()
Dispose of the NetworkVariable. Updates will no longer be sent or received, and any internal references to the variable will be removed.
Declaration
public void Dispose()
Remarks
Only use this if you are sure you no longer need the variable.
MakeDirty()
Force the variable to send an update throughout the network.
Declaration
public void MakeDirty()
Remarks
This will not trigger the OnValueChanged event.
UpdateOwner(int[])
Update the owner of the variable.
Declaration
public void UpdateOwner(params int[] playerIdArray)
Parameters
Type | Name | Description |
---|---|---|
int[] | playerIdArray | The in-game id(s) of the client(s) to make the owner(s) of the variable. |
Remarks
Can only be used by the server, and will be ignored if the LNetworkVariableWritePerms is not LNetworkVariableWritePerms.Owner.
UpdateOwner(ulong[])
Update the owner of the variable.
Declaration
public void UpdateOwner(params ulong[] clientGuidArray)
Parameters
Type | Name | Description |
---|---|---|
ulong[] | clientGuidArray | The NGO guid(s) of the client(s) to make the owner(s) of the variable. |
Remarks
Can only be used by the server, and will be ignored if the LNetworkVariableWritePerms is not LNetworkVariableWritePerms.Owner.
Events
OnValueChanged
A callback that runs when the value of the variable changes.
Declaration
public event Action<TData, TData>? OnValueChanged;
Type Parameters
Type | Description |
---|---|
TData | The previous value. |
TData | The new value. |