Why is there no Boolean net data type?

I just spent the last hour fixing a bug due to using ReadBit on a boolean, which the wiki advised me to use for booleans.

From what I understand the Bit net data type converts booleans to either a 1 or a 0, however if you then try to relay that ( client -> server -> broadcast )
you run into a subtle problem where you always receive a 1 on the other end.

I haven’t seen the code to do Bit handling but I assume it looks something like



function WriteBit( data )
    if( data ) then
        1
    else
        0
end


which would be bad because then a number will always satisfy that condition.

is this true? where’s the code for this?



O'--send
net.WriteString("true")

-- receive
bool = tobool(net.ReadSting())


What about this instead?
This is what I do for networking bools

edit:
I’m an idiot :v: don’t do this

I fixed my problem, I just am annoyed that the problem happened in the first place. It should not have.

edit:
plus that’s less bandwidth efficient than



net.WriteBit(true)
bool = tobool(net.ReadBit())


which should happen implicitly…

I’m not sure you understand data types.

Haha, I’m not good with nets and I’m lazy so I just did that.
I need to learn more haha.
I’m an idiot.

Oh shit, I didn’t know write bit existed :v:
holy fuck I’m retarded…

Isnt there WriteBool()?

fairly sure it exists

It doesn’t exist for net library, the reason why I did readstring and writestring was because I thought no bool version existed.

It does, just not part of the net library.

[editline]12th July 2014[/editline]

Bit should satisfy everything net-boolean related.

Maybe there should be a boolean variant and make the bit part deprecated as it is basically a boolean representation?

[LUA]

function net.WriteBool( bool )
net.WriteBit( bool )
end

function net.ReadBool()
return net.ReadBit() == 1
end

[/LUA]

dear god. I now live in a world where programmers think that the ability to write individual bits is “deprecated” and is only a less useful way to represent booleans.

Many languages actually represent booleans as bytes, where 11111111 is true and 00000000 is false.

the CPU can not address anything smaller than 1 byte, so really you are not writing bits. If you were, you would have to write 8 bits (1 byte) each time you called net.WriteBit(true) which would write 1 boolean (1 boolean is 8 bits in C++)

I think representing a boolean as a bit is the correct way to do it, however I think the net library should do a two way conversion… Bool-bit-bool
I shouldn’t have to explicitly parse the bit as bool.

Why not? You would still be doing net.WriteBool(true)

Yeah but then I would write

net.ReadBit()
Instead of
tobool(net.ReadBit())

You don’t need tobool unless you explicitly need a Boolean which you won’t since Lua is typeless. Readbit will return a 1 or 0 which will evaluate the same way a Boolean would

Not if you try relaying the data twice through the net library, see first post…

Interesting. It would seem as though there is loss somewhere which is a. I’m at work so ill run some tests when I get home. But we dont need read/writebool.

Although that’s what the title of my post… I don’t think so either. I just think the data in should be the same as the data out.

It seems that somewhere there is a problem with handling bits. Like I said ill run some tests when I get home and let you know how it goes.