• Variables not being attached.
    7 replies, posted
If I send a lot of floats from server to client and try to attach them it doesn't attach the actually variables Code [lua] net.Receive("updateXPBarPosCL", function() local ply = LocalPlayer(); local x = net.ReadFloat() local y = net.ReadFloat() local z = net.ReadFloat() local e = net.ReadFloat() local l = net.ReadFloat() local k = net.ReadFloat() local o = net.ReadFloat() local p = net.ReadFloat() print(x) ply.xPosBarWidthIn = x ply.yPosBarWidthIn = y ply.xXpTextPos = z ply.yXpTextPos = e ply.xLvlTextPos = l ply.yLvlTextPos = k ply.xpFontSize = o ply.lvlFontSize = p print("RECV CL GOT IT FFS", ply.xPosBarWidthIn, ply.yPosBarWidthIn, ply.xXpTextPos, ply.yXpTextPos, ply.xLvlTextPos, ply.yLvlTextPos, ply.xpFontSize, ply.lvlFontSize); end) [/lua] And here is the print [code] 580 RECV CL GOT IT nil nil nil nil nil nil nil nil [/code] I can't come up with why it doesn't attach so any help would be nice
Show your net.Start code. For each of the net.ReadX there needs to be a net.Write from where the data was sent from. [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/networking/networking_booleans.lua.html[/url] [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/networking/networking_channels_and_the_order_things_are_sent.lua[/url]
I know that [lua] function meta:updateXPBarPos( x, y, z, e, l, k, o, p ) net.Start("updateXPBarPosCL"); net.WriteFloat(x); net.WriteFloat(y); net.WriteFloat(z); net.WriteFloat(e); net.WriteFloat(l); net.WriteFloat(k); net.WriteFloat(o); net.WriteFloat(p); net.Send(self) end [/lua]
Just send a table of floats, it would be a whole lot easier.
[QUOTE=Klaes4Zaugen;46480196]I know that [lua] function meta:updateXPBarPos( x, y, z, e, l, k, o, p ) net.Start("updateXPBarPosCL"); net.WriteFloat(x); net.WriteFloat(y); net.WriteFloat(z); net.WriteFloat(e); net.WriteFloat(l); net.WriteFloat(k); net.WriteFloat(o); net.WriteFloat(p); net.Send(self) end [/lua][/QUOTE] check if you function is sending correct values in first place
And have you defined the arguments?
You need to read the variables the same way you send them, otherwise it will read them in the incorrect order. if you're not receive anything, try printing the variables before you send them and when you receive them.
[code]if ( SERVER ) then util.AddNetworkString( "updateXPBarPosCL" ); function META_PLAYER:updateXPBarPos( x, y, z, e, l, k, o, p ) net.Start( "updateXPBarPosCL" ); net.WriteFloat( x ); net.WriteFloat( y ); net.WriteFloat( z ); net.WriteFloat( e ); net.WriteFloat( l ); net.WriteFloat( k ); net.WriteFloat( o ); net.WriteFloat( p ); net.Send( self ) end concommand.Add( "dev_nettest", function( _p, _cmd, _args ) _p:updateXPBarPos( 1, 2, 3, 4, 5, 6, 7, 8 ); end ); else net.Receive("updateXPBarPosCL", function( ) local ply = LocalPlayer( ); local x = net.ReadFloat( ); local y = net.ReadFloat( ); local z = net.ReadFloat( ); local e = net.ReadFloat( ); local l = net.ReadFloat( ); local k = net.ReadFloat( ); local o = net.ReadFloat( ); local p = net.ReadFloat( ); print( x ); ply.xPosBarWidthIn = x; ply.yPosBarWidthIn = y; ply.xXpTextPos = z; ply.yXpTextPos = e; ply.xLvlTextPos = l; ply.yLvlTextPos = k; ply.xpFontSize = o; ply.lvlFontSize = p; print("RECV CL GOT IT FFS", ply.xPosBarWidthIn, ply.yPosBarWidthIn, ply.xXpTextPos, ply.yXpTextPos, ply.xLvlTextPos, ply.yLvlTextPos, ply.xpFontSize, ply.lvlFontSize); end ) end[/code] Just tested and it works: ] dev_nettest 1 RECV CL GOT IT FFS 1 2 3 4 5 6 7 8 It can be shortened by simply changing the entire receiver from local x, etc.... ( you can do it on 1 line, or just read straight into the vars ) [code] net.Receive("updateXPBarPosCL", function( ) local ply = LocalPlayer( ); ply.xPosBarWidthIn = net.ReadFloat( ); ply.yPosBarWidthIn = net.ReadFloat( ); ply.xXpTextPos = net.ReadFloat( ); ply.yXpTextPos = net.ReadFloat( ); ply.xLvlTextPos = net.ReadFloat( ); ply.yLvlTextPos = net.ReadFloat( ); ply.xpFontSize = net.ReadFloat( ); ply.lvlFontSize = net.ReadFloat( ); end );[/code] I prefer tables for stuff like this ( Instead of all those straggling vars attached to the player, have it in a master table... ) Also, naming variables something easy to understand helps too so if we need to move things around just to make insertion easy on the sending end, it is hard to get mixed up. With single char vars that aren't descriptive of what they're for, well it is easy to get lost. Take a look at the difference for output: ] dev_nettest RECV CL GOT IT FFS [bar] [x] = 1 [y] = 2 [lvl_text] [size] = 8 [x] = 5 [y] = 6 [xp_text] [size] = 7 [x] = 3 [y] = 4 and code: [code]if ( SERVER ) then util.AddNetworkString( "updateXPBarPosCL" ); function META_PLAYER:updateXPBarPos( bar_x, bar_y, xp_x, xp_y, lvl_x, lvl_y, xp_size, lvl_size ) net.Start( "updateXPBarPosCL" ); net.WriteFloat( bar_x ); net.WriteFloat( bar_y ); net.WriteFloat( lvl_x ); net.WriteFloat( lvl_y ); net.WriteFloat( lvl_size ); net.WriteFloat( xp_x ); net.WriteFloat( xp_y ); net.WriteFloat( xp_size ); net.Send( self ); end concommand.Add( "dev_nettest", function( _p, _cmd, _args ) _p:updateXPBarPos( 1, 2, 3, 4, 5, 6, 7, 8 ); end ); else net.Receive("updateXPBarPosCL", function( ) local _p = LocalPlayer( ); _p.__XPBar = { bar = { x = net.ReadFloat( ); y = net.ReadFloat( ); }; lvl_text = { x = net.ReadFloat( ); y = net.ReadFloat( ); size = net.ReadFloat( ); }; xp_text = { x = net.ReadFloat( ); y = net.ReadFloat( ); size = net.ReadFloat( ); }; }; // My print handles all data formats; look at my dev base to see how.. it makes a useful debug tool. print( "RECV CL GOT IT FFS", _p.__XPBar ); end ); end[/code] It can still be made shorter... We could use a table instead of all the floats ( which should be ints by the way ) To understand how the bit number is used take a look at how to count bits ( from right to left ); also note that 1 extra bit is used if WriteInt is used so that the +/- is signed. If you use WriteUInt then it is unsigned and the extra bit isn't needed: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/__documentation/bit_counting.lua.html[/url] - [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/__documentation/bit_counting.lua[/url] For x/y with resolutions going to 2000 - 4000 now a-days... You could just use 32 bits but that would support a super large number. Take a look at the bit-counting example ( the one at bottom shows up to 32 bit count; notice the pattern, the sum of the count is always ( 2^ ( x + 1 ) ) - 1; ) The provided net code also shows what happens when you overflow at the 32 bit mark. Hopefully this helps
Sorry, you need to Log In to post a reply to this thread.