From GMod Wiki
(Difference between revisions)
|
|
Line 1: |
Line 1: |
| __NOTOC____NOTOC__ | | __NOTOC____NOTOC__ |
| + | {{AttentionSevere|text=Datastream is being removed from garrysmod once the GMod Beta 13 update becomes public}} |
| {{Article| | | {{Article| |
| category = Lua | | | category = Lua | |
Latest revision as of 23:38, 2 December 2011
| Datastream is being removed from garrysmod once the GMod Beta 13 update becomes public |
Lua: Datastream : Client to Server |
Description: | This is explains how to use datastream to send data to the server from the client. |
Original Author: | Yoft |
Contributors: | The community |
Created: | March 8, 2009 |
Description | Sends data to the server. |
Used on | |
Code | require("datastream")
datastream.StreamToServer( "ExampleStream", { "Hi, I'm a string!", 1 } ) |
Output | Sends "Hi, I'm, a string!"(String) and 1(Number) to the server. |
Description | Receive data from a client (This goes along with the previous example) |
Used on | |
Code | require("datastream")
function exampleStreamHandler( sender, handler, id, encoded, decoded )
Msg("Datastream received:\n")
Msg("Sender: "..sender:Nick().."\n") --Our sender's name.
Msg("Handler: "..handler.."\n") --Stream's handler (AKA Stream name), in our case, 'ExampleStream'.
Msg("Data 1: "..decoded[1].."\n") --The first entry in the 'decoded' table, which is "Hi, I'm a string!".
Msg("Data 2: "..decoded[2].."\n") --The second entry in 'decoded' table, which is 1.
end
datastream.Hook( "ExampleStream", exampleStreamHandler ) |
Output | Datastream received:
Sender: (Sender's Name)
Handler: ExampleStream
Data 1: Hi, I'm a string.
Data 2: 1 |