• Best way to communicate inbetween Client and server?
    6 replies, posted
Hello! I was doing clientside stuff since i began learning lua so i am new to this. What is the best way to share as example a strinf inbetween client and server? Or access a function serverside from the client or similar? Thanks
I'm not sure I understand exactly what you mean.. But try using [URL="http://wiki.garrysmod.com/page/net/Send"]net.Send[/URL] and [URL="http://wiki.garrysmod.com/page/net/Receive"]net.Receive[/URL]
[URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]Here is a tutorial for net[/URL] [URL="http://wiki.garrysmod.com/page/Networking_Entities"]If you do not use a lot, use can also use Networked variables[/URL]
[CODE] if SERVER then util.AddNetworkString( "this_is_required_for_each_net_message" ) -- a net message must be added by name through util.AddNetworkString before being used net.Start( "this_is_required_for_each_net_message" ) --net messages are identified by name net.WriteString( "you can write strings" ) net.WriteInt( 69, 8 ) --numbers, second arg specifies the number of bits to write in the second arg. net.WriteTable( { "bob", 1, 0.005 } ) --tables are ez net.Send( player.GetAll() ) --can send to a table of players or just a single player else net.Receive( "this_is_required_for_each_net_message", function( length ) --length is the number of bits print( net.ReadString() ) --data must be read in the order that it's written print( net.ReadInt( 8 ) ) --ints must send and receive the same number of bits PrintTable( net.ReadTable() ) end ) end [/CODE]
[QUOTE=CallMePyro;45685277][CODE] if SERVER then util.AddNetworkString( "this_is_required_for_each_net_message" ) -- a net message must be added by name through util.AddNetworkString before being used net.Start( "this_is_required_for_each_net_message" ) --net messages are identified by name net.WriteString( "you can write strings" ) net.WriteInt( 69, 8 ) --numbers, second arg specifies the number of bits to write in the second arg. net.WriteTable( { "bob", 1, 0.005 } ) --tables are ez net.Send( player.GetAll() ) --can send to a table of players or just a single player else net.Receive( "this_is_required_for_each_net_message", function( length ) --length is the number of bits print( net.ReadString() ) --data must be read in the order that it's written print( net.ReadInt( 8 ) ) --ints must send and receive the same number of bits PrintTable( net.ReadTable() ) end ) end [/CODE][/QUOTE] I understand you're trying to help, but instead of over-simplifying things the OP should just read the wiki page provided above.
[QUOTE=kibble;45685564]I understand you're trying to help, but instead of over-simplifying things the OP should just read the wiki page provided above.[/QUOTE] But that's pretty much all he needs for net messages. What else is there to add?
[QUOTE=HumbleTH;45686361]But that's pretty much all he needs for net messages. What else is there to add?[/QUOTE] There is quite a bit more on the wiki article, with proper explanations, than CallMePyro provided. I'm not hating on him for trying to help, but watering down code so it is easier for him to take in will just make him come back when he is looking to use it in more complex situations.
Sorry, you need to Log In to post a reply to this thread.