Question regarding net.WriteString(tostring(number))

This is something mentioned when attempting to submit anything to, for example, gmodstore, but you’re not allowed to do net.WriteString(tostring(number)) anywhere in your script.

Why is this? They say you have to use net.WriteInt/Double/Float/etc and not WriteString with a tostring return. From my experience writing my own shit, I’ve found the trick to be invaluable, but I’m assuming gmodstore doesn’t require that for no reason.

So, what’s the reason? Should I quit doing so in my own work, even though I don’t plan on selling a script on any site?

It’s inefficient. There’s no reason to not use


First of all, it creates two unnecessary function calls, tostring() on the server then tonumber() on the client or vice versa.

Secondly, if I’m not mistaken sending a number is a lot less costly than sending a string.

Like how inefficient, though? Not so much, so that the only decent argument against doing so is because it’s a bad coding habit? Or enough that it can put a noticeable strain on lower-end PCs?

Not trying to sound condescending, so if I come off sounding so, it’s not my intent.

It’s a bad coding habit and it gives you as a coder less credibility. I guess it’s also more prone to exploiting because string data could be sent resulting in unexpected behavior. It also makes the code less readable.
There’s no reason to use your method over WriteInt, it’s not faster to write and it occupies a lot more space in the data packets being sent. If you’re sending the messages a lot it’s definitely bad.

Well, it’s not like you’re going to have a high cost, but let’s imagine that you are sending 53020 to server, once you write bytes to send to server, it will write 53 51 48 50 48, but if you send the number as it, then it will send 53020 and it base, let’s say 32, it’s way efficent than calling 3 functions when you can just do it in 1 step

It’s extremely more network inefficient - each string character is 8 bits + 32 bits (iirc) for the string length. An integer at most with WriteInt is 32 bits, so your minimum network bloat is 8 * string length bits.