What to use instead of NWBool()?

So, I heard that using things such as NWBool and Int are inefficient. Is this true?

What are other methods I have been looking at other ways such as net.WriteBit and net.ReadBit also would be net.WriteBool be a viable option?
The scenario is I am trying to get “ent.cancollect” (which is in my init.lua) to go over to cl_init.lua so it can change things depending on whether it is true or false. Originally I would use NWBool but apparently it is inefficient.

NOTE: “ent.cancollect” can be true or false like so “ent.cancollect = true”. However, this is set in the init.lua.
NOTE2: the “ent.cancollect” is inside a net.Receive(“example”) in the init.lua and is being called by a derma button in cl_init like so:



net.Start("example")
	net.WriteEntity( ent )
net.SendToServer()

honestly ent:SetNWBool(“CanCollect”, true ) would be the simplest solution to the problem, nwvars are only inefficient when used in an inefficient way.

eg each player has a stamina stat that changes every tick. You can only see your own stamina bar thus you are the only one that needs to know how much stamina you have.
Using a nwvar for that would send your stamina to all 10 players every single time it changes which is every tick.

This makes 10 players x 10 synced variables = 100 data packets sent every tick.
If you use net to only send a persons stamina to them alone then 10 players x 1 var per player = 10 data packets sent every tick

In your case though you need an entitys cancollect status to be visible to anybody that could potentially walk near it, plus its only a boolean and only changes periodically so you could safely use SetNWBool without any noticable loss in performance or bandwidth

Hmmm, thanks for the reply. It make sense now, because this only only be changed once every few minutes it should be okay? Thanks

This could be of use to you.

Networking Entities

Wow, that is really useful thank you :slight_smile:

EDIT:
I am guessing this is why I cannot have a NWBool inside of a net.Receive? Because they are 2 different things?

[editline]15th August 2015[/editline]

Thanks, I am doing to look at them now and play around with them a bit? Unless you have a method on how to use them?

actually you can although there’s rarely any valid reason why you would do so

client:
net.Start(“poop”)
net.WriteString(“dank memes”)
net.SendToServer()

server:
net.Receive(“poop”, function( ply, len )
local str = net.ReadString()
ply:SetNWString( “thisisprettystupid”, str )
end)

Ahhh right, did not know that, cheers :slight_smile: