Ok, let me try to explain: the
network argument is passed in a different function for each side of the NetVars hook.
When the server is creating the network variables,
network(var) pushes var onto the queue of variables to send off. It then returns that same variable for a reason I'll get to shortly.
When the client is receiving the network variables,
network() pulls the first variable from the queue and returns it. I don't think it necessarily takes an argument, but it won't hurt anything to pass one in.
Therefore, the proper use of the function is
variable = network(variable). This will store the variable on the server's side, and read it on the client's side, seamlessly. Due to the way this works, it's important that the type and order of variables read is exactly the same on both sides; if that type/order can vary in any way, you need to store that information inside the variable queue itself. For instance, if you need to store a variable amount of numbers for, say, a list of scores on a map:
local scores = {} -- Example list, pretend it gets filled in elsewhere in the script
addHook("NetVars", function(network)
local scoreCount = #scores -- This will get overridden shortly for the client, so it's ok
scoreCount = network(scoreCount)
for i = 1, scoreCount do
scores[i] = network(scores[i])
end
end)
You can apply similar logic to send other kinds of lists/tables/etc. I don't recall exactly what kinds of variables can be sent across the NetVars hook (maybe the wiki lists it? I've never looked up the hook because it was broken the last time I needed to use it) but be aware that some things might not be directly transferrable. In those cases you'll have to get creative.
Also note that variables inside player/mobj structs are networked automatically, so you only need the NetVars hook for variables that aren't stored in one of those.