ActiveNetwork library
Part of Active Network
ActiveNetwork keeps variables in sync between the server and its clients.
The server sets global variables with ActiveNetwork.set_nv and the variables of an entity
with Entity:set_nv. Every change is sent to clients over Cable, where
ActiveNetwork.get_nv and Entity:get_nv return the last value received. Values only
travel from the server to clients, and anything can be networked except for a function
and a table that has a function anywhere inside of it.
Player:sync_nv sends everything that is currently set to a single player, which Flux does
for every player once their client has created its local player.
A variable is public until a setter is given recipients, which makes it private: from then
on its value is only ever sent to those players, whether by a later update, by
Entity:send_net_var or by Player:sync_nv, until Entity:set_nv_recipients or
ActiveNetwork.set_nv_recipients changes that. Player:set_private_nv sets a variable of a
player that nobody but that player receives. Recipients are player entities, so a player
who reconnects is not a recipient any more.
Summary
Functions
Functions
Returns the value of a networked global variable.
Parameters
- key String variable name
- default Any optional, defaults to
nilvalue to return if the variable is not set
Returns
- Any variable value, or default
Defined in
Returns the players a networked global variable is sent to.
Parameters
- key String variable name
Returns
- List<Player> recipients who are still on the server, or nil if the variable is public
On the server
Sets a networked global variable and sends it to clients. Does nothing if neither the value nor the recipients have changed. Functions and tables that contain functions cannot be networked.
Parameters
- key String variable name
- value Any new value, anything but a function or a table that contains one
- send Player/List<Player> optional, defaults to
nilmakes the variable private: these players become its only recipients, and everyone else is told to forget it. If nil, the value goes to the current recipients of the variable, which is everyone unless it is private
On the client
Does nothing. Networked globals cannot be set on the client.
Parameters
- key
- value
- send
Defined in
ActiveNetwork.set_nv_recipients(key, send)
server packages/active_network/lib/sv_active_network.lua:244Changes who a networked global variable is sent to without changing its value. Players who stop being recipients are told to forget the value, and the current value is sent to the new recipients. The recipients can be set before the variable itself, which makes sure that its first value does not reach anybody else.
-- Only this player will ever receive the variable.
ActiveNetwork.set_nv_recipients('fl_secret', actor)
ActiveNetwork.set_nv('fl_secret', 42)
-- Make it public again.
ActiveNetwork.set_nv_recipients('fl_secret', nil)
Parameters
- key String variable name
- send Player/List<Player> optional, defaults to
nilthe only players to send the variable to; nil makes it public