• Writeint is only sending -2
    19 replies, posted
Hey, [code] net.Start("SetPlayerModel") net.WriteString(NewName:GetText()) net.WriteInt(TeamNum,2) net.SendToServer() [/code] is only sending -2 to the server. TeamNum is a single int Thanks soo much
You're sending an integer with a width of 2 bits ( not bytes ). Change it to 16.
still doesnt work, it sends another random number
Show your receiving code and the value of TeamNum too.
WriteInt sends a signed integer ( signed meaning it has a + or - associated with it, while unsigned doesn't ). With a signed integer, you lose 1 bit of potential data so if you send 2 bits which would normally allow for a number up to 3, you would only be able to get -1, 0 or +1, a range of 2 if shifted because of the bit being lost from the sign. If you're always sending a positive, or always a negative, you'd be better off using an unsigned integer, and correcting / placing the sign on the incoming data yourself. Here's a small tutorial on bit counting: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/networking/bit_counting.lua.html[/url]
[QUOTE=Acecool;46609836]WriteInt sends a signed integer ( signed meaning it has a + or - associated with it, while unsigned doesn't ). With a signed integer, you lose 1 bit of potential data so if you send 2 bits which would normally allow for a number up to 3, you would only be able to get -1, 0 or +1, a range of 2 if shifted because of the bit being lost from the sign. If you're always sending a positive, or always a negative, you'd be better off using an unsigned integer, and correcting / placing the sign on the incoming data yourself. Here's a small tutorial on bit counting: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/networking/bit_counting.lua.html[/url][/QUOTE] you realize sending an unsigned int is the same as sending a signed int right (in glua/source engine)
[QUOTE=MeepDarknessM;46609846]you realize sending an unsigned int is the same as sending a signed int right (in glua/source engine)[/QUOTE] [code]] lua_run net.Receive( "Signed", function() print( net.ReadInt( 8 ) ) end ) > net.Receive( "Signed", function() print( net.ReadInt( 8 ) ) end )... ] lua_run net.Receive( "Unsigned", function() print( net.ReadUInt( 8 ) ) end ) > net.Receive( "Unsigned", function() print( net.ReadUInt( 8 ) ) end )... ] lua_run_cl net.Start( "Unsigned" ) net.WriteUInt( 255, 8 ) net.SendToServer() 255 ] lua_run_cl net.Start( "Signed" ) net.WriteInt( 255, 8 ) net.SendToServer() 127 [/code] It's not, unless I'm somehow misunderstanding?
With signed you lose 1 bit because of the +/- sign. Joey's example shows this as does my example at the bottom of the bit-counting. It may be that in the engine, they automatically add 1 bit for the sign when it is sent, or they don't, I don't know because I haven't seen the code but I'd be interested to see what you're talking about.. Using this net system we lose one bit and have to make up for it ourselves.
[QUOTE=Acecool;46609923]With signed you lose 1 bit because of the +/- sign. Joey's example shows this as does my example at the bottom of the bit-counting. It may be that in the engine, they automatically add 1 bit for the sign when it is sent, or they don't, I don't know because I haven't seen the code but I'd be interested to see what you're talking about.. Using this net system we lose one bit and have to make up for it ourselves.[/QUOTE] An 8-bit signed integer will network 8 bits of data. No separate bit is sent alongside it, but the most significant bit is definitely used for the sign. Saying that the bit is "lost" is fairly misleading because there's still 2^n combinations of numbers you can make.
[QUOTE=Acecool;46609923]With signed you lose 1 bit because of the +/- sign. Joey's example shows this as does my example at the bottom of the bit-counting. It may be that in the engine, they automatically add 1 bit for the sign when it is sent, or they don't, I don't know because I haven't seen the code but I'd be interested to see what you're talking about.. Using this net system we lose one bit and have to make up for it ourselves.[/QUOTE] What you're saying is either wrong or misleading. 0 to 255 for unsigned -128 to 127 for signed The range of numbers is 256 for both, and they both use the same amount of bits; you just start and end at different numbers.
Actually, you're right in that definition ( and I mention that at the bottom of my tutorial in regards to shifting the values to get the full scope ) but without shifting you're left with 1 bit "less".
[QUOTE=Acecool;46609836]With a signed integer, you lose 1 bit of potential data so if you send 2 bits which would normally allow for a number up to 3, you would only be able to get [B]-1, 0 or +1[/B], a range of 2 if shifted because of the bit being lost from the sign.[/QUOTE] that would be -2, -1, 0 and 1
The sign bit doesn't only mean that the number is negative. It works the same as any other bit except it's weight is negative. 111 = -4 + 2 + 1= -1 101 = -4 + 1 = -3
[QUOTE=Joeyl10;46609888][code]] lua_run net.Receive( "Signed", function() print( net.ReadInt( 8 ) ) end ) > net.Receive( "Signed", function() print( net.ReadInt( 8 ) ) end )... ] lua_run net.Receive( "Unsigned", function() print( net.ReadUInt( 8 ) ) end ) > net.Receive( "Unsigned", function() print( net.ReadUInt( 8 ) ) end )... ] lua_run_cl net.Start( "Unsigned" ) net.WriteUInt( 255, 8 ) net.SendToServer() 255 ] lua_run_cl net.Start( "Signed" ) net.WriteInt( 255, 8 ) net.SendToServer() 127 [/code] It's not, unless I'm somehow misunderstanding?[/QUOTE] [code] ] lua_run util.AddNetworkString("ubits") net.Receive("ubits", function() print(net.ReadUInt(32)) end);lua_run util.AddNetworkString("bits") net.Receive("bits", function() print(net.ReadInt(32)) end) > util.AddNetworkString("ubits") net.Receive("ubits", function() print(net.ReadUInt(32)) end)... > util.AddNetworkString("bits") net.Receive("bits", function() print(net.ReadInt(32)) end)... ] lua_run_cl net.Start("ubits") net.WriteInt(0x80000000, 32) net.SendToServer() -2147483648 ] lua_run_cl net.Start("ubits") net.WriteUInt(0x80000000, 32) net.SendToServer() -2147483648 ] lua_run_cl net.Start("bits") net.WriteUInt(0x80000000, 32) net.SendToServer() -2147483648 ] lua_run_cl net.Start("bits") net.WriteInt(0x80000000, 32) net.SendToServer() -2147483648 [/code]
[url]https://github.com/Facepunch/garrysmod-issues/issues/1485[/url]
[QUOTE=Willox;46612967][url]https://github.com/Facepunch/garrysmod-issues/issues/1485[/url][/QUOTE] pretty sure it means it is just a wrong cast (signed int not unsigned)
Could use writedouble if writeint confuses you.
[QUOTE=AIX-Who;46614837]Could use writedouble if writeint confuses you.[/QUOTE] now that only sends 2.1621686542012e+190 It wont work :( and also, i'm making a weapon and it doesnt load, unless I Lua refresh it.. :o and also how do you [B]CHANGE[/B] someones name?
The reason it only works when you refresh is because of what happens on auto-refresh... Imagine you have a file and these are the contents. [code]print( test ); test = 123;[/code] The first time it loads, it'll print a new-line, but nothing else because test wasn't initialized. On Auto-refresh, because everything from before is still in memory, it will print 123. You have something similar going on with your weapon. Look for an error, or figure out if you're calling a function in the file before another function is initialized... Imagine this file: [code]function test( ) test2( ); end test( ); function test2( ) print( 123 ); end[/code] It will give an error because test2 wasn't initialized because test calls test2 but test( ) was called before test2 was initialized. The difference with this one is that when an error occurs, it should stop so you shouldn't have this type of error, but you may something similar to example 1 or another issue. Enable -condebug in the launch options of your SRCDS ( don't use listen server, if you need help setting up local SRCDS read this: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/server_srcds_steamcmd/setting_up_a_server_with_steamcmd.lua.html[/url] ) and look for an error or post it here.
In case you were all wondering, Ive fixed this error. I was setting variables a specific way around (net.int then net.string) but apparently using net.int first mattered and broke the function.
Sorry, you need to Log In to post a reply to this thread.