• What am I missing here? (networked vars)
    10 replies, posted
[lua] hook.Add( 'PlayerInitialSpawn', 'facepunch', function( ply ) ply:SetNWInt( "banana", 0 ) print( ply:GetNWInt( "banana", 0 ) ) -- prints 0 like it needs to end) hook.Add( 'PlayerDeath', 'facepunch death', function( ply, inf, atk ) ply:SetNWInt( "banana", ply:GetNWInt( "banana", 0 ) + 1 ) print( ply:GetNWInt( "banana", 0 ) ) -- prints 0 first time, while it should be 1 ( 0 + 1 = 1 ), it lags 1 behind all the time even with a timer of 10 minutes. Using NWFloat doesn't solve this either end) [/lua] Any ideas?
What's the problem? Does it always print 0? If so it's because you have to put ply:GetNWInt( "banana" ) I believe.
No, the second parameter is a fallback option in case it's nil. The problem is that it's lagging behind by 1.
So when they die 2 times it's set to 1?
NWVar sync isn't instant, why does this matter to you?
-snip-
I've put a timer of one minute because I did think its sync isn't instant, it still lagged. It is even lagging on the server realm. ( like in the example )
Why use NWvar in the first place? I assume you are just trying something, but wouldn't it be just easier to use something that you should use anyways - net library. Sorry if it's missing the point though
Net library would be pretty redundant since it is unique to every player and sending it every time someone dies seems pretty odd. It will make this much much more complicated than they should be to be honest My current solution is just add a +1 to where I get the var. Seems pretty stupid since it shouldn't do that, but I'm still keepin this thread just to know why it happens and if I'm the only one
Is all of this code serverside or shared?
Also... why are you using NWvars if you are only using these vars serverside O_O ? Wouldn't it be just easier to do. [lua]hook.Add( 'PlayerInitialSpawn', 'facepunch', function( ply ) ply.Banana = 0 print ( ply.Banana ) end) hook.Add( 'PlayerDeath', 'facepunch death', function( ply, inf, atk ) ply.Banana = ply.Banana + 1 print ( ply.Banana ) end)[/lua] Also, net library is way more efficient. Also it doesn't seem to be this complicated, heres an example: [lua]//Serverside util.AddNetworkString( 'NET_BananaCount' ) hook.Add( 'PlayerInitialSpawn', 'facepunch', function( ply ) ply.Banana = 0 print ( ply.Banana ) net.Start( 'NET_BananaCount' ) net.WriteInt( ply.Banana, 16 ) net.Broadcast() -- or net.Send( ply ) if only want to send it to the player end) hook.Add( 'PlayerDeath', 'facepunch death', function( ply, inf, atk ) ply.Banana = ply.Banana + 1 print ( ply.Banana ) net.Start( 'NET_BananaCount' ) net.WriteInt( ply.Banana, 16 ) net.Broadcast() -- or net.Send( ply ) if only want to send it to the player end) //Clientside function someFunc() LocalPlayer().Banana = net.ReadInt( 16 ) or 0 end net.Receive( 'NET_BananaCount', someFunc )[/lua]
Sorry, you need to Log In to post a reply to this thread.