• Net library seems to send wrong numbers
    11 replies, posted
The error (and output of the print): [pre] [ERROR] addons/shooter/gamemodes/shooter/gamemode/cl_init.lua:154: bad argument #1 to 'pairs' (table expected, got nil) 1. pairs - [C]:-1 2. func - addons/shooter/gamemodes/shooter/gamemode/cl_init.lua:154 3. unknown - lua/includes/modules/net.lua:32 [/lua] 0 Server code: [lua]function GM:OnPlayerChangedTeam(ply, ot, nt) net.Start("clasui") print(nt) net.WriteFloat(nt) net.Send(ply) ply:SetPlayerColor(team.GetColor(nt)) --if ply == LocalPlayer then --end end[/lua] Client code: [lua] net.Receive("clasui", function(length, client) tframe:MakePopup() print(net.ReadFloat()) for n, c in pairs(team.GetClass(net.ReadFloat(nt))) do classList:AddLine(c) end end) [/lua]
net.ReadFloat won't have 100% accuracy since lua_Number (the default lua number type in gmod) is a double try net.Read/WriteDouble or if it's a whole number try Read/WriteUInt EDIT: i didn't realize you read two floats, read robotboy's suggestion
You write one float but you read two. Do this [code] net.Receive("clasui", function(length, client) tframe:MakePopup() local a = net.ReadFloat() print(a) for n, c in pairs(team.GetClass(a)) do classList:AddLine(c) end end)[/code]
After trying both solutions... nothing. New code: [lua] function GM:OnPlayerChangedTeam(ply, ot, nt) net.Start("clasui") print("nt - "..nt) net.WriteDouble(nt) net.Send(ply) ply:SetPlayerColor(team.GetColor(nt)) --if ply == LocalPlayer then --end end [/lua] and [lua] net.Receive("clasui", function(length, client) tframe:MakePopup() x = net.ReadDouble(nt) print(x) for n, c in pairs(team.GetClass(x)) do classList:AddLine(c) end end) [/lua]
Is there an error? What's printed? Does the net.Receive get called?
[QUOTE=code_gs;47450586]Is there an error? What's printed? Does the net.Receive get called?[/QUOTE] 1. Yes: [pre] [ERROR] addons/shooter/gamemodes/shooter/gamemode/cl_init.lua:155: bad argument #1 to 'pairs' (table expected, got nil) 1. pairs - [C]:-1 2. func - addons/shooter/gamemodes/shooter/gamemode/cl_init.lua:155 3. unknown - lua/includes/modules/net.lua:32 [/pre] 2. Nothing. I don't know why. 3. Yes, or there would be no error.
Why not write the teams as integers? Unless I'm missing something here. Also it doesn't seem like you're reading the doubles correctly, where is [B]nt[/B] defined in the clientside code?
[QUOTE=Jeezy;47450664]Why not write the teams as integers? Unless I'm missing something here. Also it doesn't seem like you're reading the doubles correctly, where is [B]nt[/B] defined in the clientside code?[/QUOTE] Tried that same error
[QUOTE=figgycity50;47450685]Tried that same error[/QUOTE] Show the code you used when you tried to write the team as an integer. I have a feeling you aren't correctly using the bits argument.
[QUOTE=Jeezy;47450692]Show the code you used when you tried to write the team as an integer. I have a feeling you aren't correctly using the bits argument.[/QUOTE] [lua] function GM:OnPlayerChangedTeam(ply, ot, nt) net.Start("clasui") print("nt - "..nt) net.WriteInt(nt, 2) net.Send(ply) ply:SetPlayerColor(team.GetColor(nt)) --if ply == LocalPlayer then --end end[/lua] There are two teams, 0 and 1
Can you post the clientside code as well? Have you tried using a larger amount of bits as well, just in case somehow the team indexes got fucked up somehow and are higher than you expected?
[QUOTE=figgycity50;47450737][lua] function GM:OnPlayerChangedTeam(ply, ot, nt) net.Start("clasui") print("nt - "..nt) net.WriteInt(nt, 2) net.Send(ply) ply:SetPlayerColor(team.GetColor(nt)) --if ply == LocalPlayer then --end end[/lua] There are two teams, 0 and 1[/QUOTE] [lua] function GM:OnPlayerChangedTeam(ply, ot, nt) print("nt - "..nt) net.Start("clasui") net.WriteUInt(nt, 8) -- 8 bits, unsigned net.Send(ply) ply:SetPlayerColor(team.GetColor(nt)) -- Doesn't this function take a VECTOR? end[/lua] [lua] net.Receive("clasui", function(length, client) x = net.ReadUInt(8) print("GOT EM: " .. x) for n, c in pairs( team.GetClass(x) ) do classList:AddLine(c) end tframe:MakePopup() end)[/lua] Use this. Look for GOT EM: number in your CLIENT console. Make sure you set up classes SHARED, not only serverside. [editline]3rd April 2015[/editline] net.Receive MUST BE OUTSIDE OF ANY OTHER FUNCTION
Sorry, you need to Log In to post a reply to this thread.