Jump to content

[Scripting] Help with netvars

Recommended Posts

What I'm trying to do:

-Have the host choose some configurations and store the settings somewhere

-Have the client download those settings and use them


I'm a bit confused about where things are stored and retrieved from as well as just basic syntax. For example if in modmain.lua as a host I had:

net_size = net_int(inst.GUID, "size", "size_dirty")net_size:set(1)

Can the client get at it by doing:

local size = net_size:value()

And can this be done in the modmain.lua or would I have to go about it like in The Hunt mod and create a component with a class and hook it all in that way? Also, what -is- the proper syntax for creating the net variable, assigning a value, and retrieving a value if any of the above is off the mark?

Link to comment
Share on other sites

@GhostRequiemZX, net_vars have to be attached to a specific entity, and for them to be accessible, that entity has to be getting synced with the clients (so for example, if you attach it to a random fireplace, and the client is far from the fireplace, they won't be accessible because the fireplace isn't part of that client's "awake" space).


I'm not totally sure what you're trying to do, but if you want to propagate mod config options, a solution to that is on the way-- one of the next few patches should do that automatically for mods that have all_clients_require_mod = true.


If that's not what you're trying to do, or really want it to work now, you could attach the net_vars to the world or the world_network, since that propagates to clients. You can take a look at the components that are attached to the world_network to see how it's doing that, but basically you'd attach them in something like this, I think:

AddPrefabPostInit("world_network", function(inst)    inst.mymod_size = net_int(inst.GUID, "mymod_size", "mymod_size_dirty")end)

It's a good idea to attach some sort of little mod identifier on there at the start of your net_var name and event, since you're attaching it to a central entity that other mods could be attaching stuff to.

Link to comment
Share on other sites

Thanks again rezecib, what you're describing about the propagation of mod config options is exactly what I want to do. Since a more simplistic solution is on the way I'll wait until then.


For now, thanks a lot for the explanation on the net_var and naming etiquette. I'll store those in my toolbox for a rainy day.

Edited by GhostRequiemZX
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...