Last active
January 10, 2016 08:19
-
-
Save SwadicalRag/a42d30f96849e1944ffc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
won't work if another message is sent in between wait call and rest of data 👎