Optimizing NWInts/NWBools

What’s the best way to optimize lots of NWInts/NWBools using the net library?

Rather than just doing that, do I have to Broadcast every time I change the nwint/bool?

I don’t see the better way to do store lots of ints and bools on the client / server, perhaps somebody can point me in the direction?

The net library is much better than networked variables, it is faster, the space limit is Much higher, and NWvars queue up(which can cause problems in servers with around 40+ people) while the net library sends information straight to the client right then and there.

You should learn how to use the net library, and use it for any future networked objects. Leaving a few old style NWvars won’t hurt any kind of performance, which is a good idea if you do not want to go through the headache of converting over entirely to the net library.

Some tips:
-Network things only when needed. Such as if you need all players to be aware of a variable unique to a certain player(cash/wins/ect) and take for example the only way to see another players cash is by opening up some menu. Network stuff then, instead of sending a message to every client every time a player earns/loses some cash.

-Try not to get to fancy if you are new to networking things. Although you can do things like creating wrappers, which is basically like making a framework for networked objects. This would be useful but a little complicated because it can help you manage your networked messages with ease.

-Don’t stress things. As long as you are sending networked variables as little as possible but only when needed you will have no problems at all.

I have never seen this tutorial before but it looks like it has all the information you should need.
Tutorial: Using The Net Library

It’d be better to tell us why you’re using lots of NWInts/Bools

I’m storing quite a bit of data on entities; such as how much money is in them, how much power they have, how much gas, etc.

I can’t think of a better way to do this, and I’m not quite sure how to do it with the net library, an example of how would be awesome.

I would be looking at using the datatables, to see if you can fit it in them. They’re a lot more optimized that the NW var stuff.

If you’re storing a lot of things - you can use the Vector and Angle slots, as seen in this entity

( the NetworkVarElement entry )

The datatables are better than NWInts/Bools? It seems like fairly the same stuff to me.

The difference between this way and the way you’re doing it is… these variables are all sent anyway. They all exist whether or not you use them. But they’re only sent when there’s a change. And they’re networked in the same way as the native entity variables are networked.

The NW* var method uses usertables. They’re sent sloppily - and periodically. The changes might be late (depending on the number of entities, they could be multiple seconds late). It also generates a lot more network traffic and overhead than the above method. The NW* methods shouldn’t really be used unless you have no other option.

Basically the datatable method is the clean method. The NW var method is a system built on a system on another system that was never really meant to do this kind of thing.

Hmmm, I’ll give it a go.

Thanks for the help.

Sounds to me that it should be replaced. Doesn’t seem like something people should even have the option to use if its so outdated by database method, even if its easier to use. It just supports sloppy work.

If I replace it now everything that will use it will break - is that what you want me to do?

Hasn’t stopped you before, :stuck_out_tongue:

What he meant was making it use the net library and only when it’s needed, instead of periodically.

Huh. I thought you’d changed NWVars to update over the new net channel?

Someone made a wrapper for it and it worked pretty good. I remember it was using usermessages and only sent data if you saw the entity or something. It stopped the buffer overflows that was a big problem back then.

Sorry for bumping, but I still don’t fully understand how to do this.

Currently; when I spawn an entity; in the Initialize function; I have SetNWInt(“Damage”, 300) per say…

Simple as? [lua]self:NetworkVar( “Int”, 300, “Damage” );[/lua]?

Then setting the values as so… self:GetDamage; self:SetDamage?

Also; it looks like you can only set 4 DT values… and how would I set DT values on a player too? :c

Check out the wiki page called DTVars. I filled it (and relevant pages) out with some basic info that should help.

Oh and never use PData, if they get corrupted you’re screwed

If anything gets corrupted you’re screwed.

[editline]4th February 2013[/editline]

That’s why god invented daily backups.