Skip to content

Instantly share code, notes, and snippets.

@SwadicalRag
Last active January 10, 2016 08:19
Show Gist options
  • Select an option

  • Save SwadicalRag/a42d30f96849e1944ffc to your computer and use it in GitHub Desktop.

Select an option

Save SwadicalRag/a42d30f96849e1944ffc to your computer and use it in GitHub Desktop.
function net.InlineMessage(id,fn)
local thread = coroutine.create(fn)
coroutine.resume(thread)
net.Receive(id,function(...)
if coroutine.status(thread) == "suspended" then
coroutine.resume(thread,...)
end
end)
end
net.WaitForReply = function(...)
if SERVER then
net.Send(...)
else
net.SendToServer()
end
coroutine.yield()
end
-- EXAMPLE USAGE
if SERVER then
util.AddNetworkString("test")
net.Receive("test",function(len,ply)
net.WriteString("Test")
net.WriteString("Memes")
net.WriteInt(net.ReadInt(10),10)
end)
else
net.InlineMessage("test",function()
net.Start("test")
net.WriteInt(69,10)
local len,ply = net.WaitForReply()
print("reply received",net.ReadString(),net.ReadString(),net.ReadInt(10))
end)
end
@meepen

meepen commented Jan 10, 2016

Copy link
Copy Markdown

won't work if another message is sent in between wait call and rest of data 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment