Net Message Integer transfer failing to work as intended
3 replies, posted
Client code and client console print
[CODE]
net.Start("RequestAvailableWeapons")
net.WriteInt(self.myRole, 4)
print("myRole DEBUG - ", self.myRole)
net.SendToServer()
myRole DEBUG - 8
[/CODE]
Server code and server console print
[CODE]
net.Receive("RequestAvailableWeapons", function(len, ply)
local plyRole = net.ReadInt(4)
local availableWeaponsTable = {}
print(plyRole)
--More stuff done underneath but cut for length's sake
end)
0
[/CODE]
What's going on here? How come the number is coming in as 0?
Maybe try increasing the bitcount?
I'll give it a go, but the highest number self.myRole can ever be is 8. 2^3 is 8. Dunno why it would return 0.
[editline]21st November 2017[/editline]
Oh I see now, it has 8 values, but the first value starts at 0, so it's 0-7 and not 1-8.
For future reference, you can check how many bits you need with this formula:
[code]math.ceil(math.log(8, 2)) + 1[/code]
Sorry, you need to Log In to post a reply to this thread.