• SetNW bug?
    8 replies, posted
Is there a current bug with all SetNW and GetNW or is mine just dont work? From the server I set a variable and when I try to access it from the client it just brings back false or 0 or whatever. [code] //Server side code Player(2):SetNWBool("activeAdmin", true) print(Player(2):GetNWBool("activeAdmin")) //This prints 'true' on the server side console [/code] [code] //Client side code print(Player(2):GetNWBool("activeAdmin")) //This always brings back 'false'. [/code]
You're using two different functions.
[QUOTE=StonedPenguin;47842929]You're using two different functions.[/QUOTE] Oh sorry copy and paste got mixed up while I was expiramenting trying to figure out what is going on. I did try the same functions, both GetNWBool and GetNetworkedBool. Both don't work.
Show more code. Tell us things like where you are calling it, etc. If you call it too soon on the client, you might be trying to fetch the value before the server even networks it to you.
[QUOTE=Revenge282;47843055]Show more code. Tell us things like where you are calling it, etc. If you call it too soon on the client, you might be trying to fetch the value before the server even networks it to you.[/QUOTE] I know this isnt the case because I try setting the value multiple times before receiving it. I print and set the values my self via refreshing the file.
You can't call Player(2) in the client. Your client has no idea what Player(2) is. Either send your client the ent you're trying to call or you can only call LocalPlayer() [CODE]--CLIENT net.Receive( "activeAdmin", function( len ) ent = net.ReadEntity() print(ent:GetNWBool("activeAdmin")) end ) --SERVER util.AddNetworkString( "activeAdmin" ) Player(2):SetNWBool("activeAdmin", true) print(Player(2):GetNWBool("activeAdmin")) net.Start( "activeAdmin" ) net.WriteEntity(Player(2)) net.Send( Player(2) ) --This makes no sense as you can just call LocalPlayer() in that client. But you can change what this is sent to.[/CODE] Use [URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]Net Library[/URL] to send information between the server and the client. To optimize the above code instead of sending the whole entity you could just send a WriteNWBool like the below but I was unclear if you wanted to continue finding info on the player [CODE]--CLIENT net.Receive( "activeAdmin", function( len ) networkedbool = net.ReadNWBool() print(networkedbool) end ) --SERVER util.AddNetworkString( "activeAdmin" ) Player(2):SetNWBool("activeAdmin", true) print(Player(2):GetNWBool("activeAdmin")) local isPlayer2Admin = Player(2):GetNWBool("activeAdmin")) net.Start( "activeAdmin" ) net.WriteNWBool(isPlayer2Admin) net.Send( Player(2) ) --This makes no sense as you can just call LocalPlayer() in that client. But you can change what this is sent to. [/CODE] This way you are only sending a true/false instead of an entire entity's data tables
[QUOTE=MGCLegend;47844183]You can't call Player(2) in the client. Your client has no idea what Player(2) is. Either send your client the ent you're trying to call or you can only call LocalPlayer() [CODE]--CLIENT net.Receive( "activeAdmin", function( len ) ent = net.ReadEntity() print(ent:GetNWBool("activeAdmin")) end ) --SERVER util.AddNetworkString( "activeAdmin" ) Player(2):SetNWBool("activeAdmin", true) print(Player(2):GetNWBool("activeAdmin")) net.Start( "activeAdmin" ) net.WriteEntity(Player(2)) net.Send( Player(2) ) --This makes no sense as you can just call LocalPlayer() in that client. But you can change what this is sent to.[/CODE] Use [URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]Net Library[/URL] to send information between the server and the client. To optimize the above code instead of sending the whole entity you could just send a WriteNWBool like the below but I was unclear if you wanted to continue finding info on the player [CODE]--CLIENT net.Receive( "activeAdmin", function( len ) networkedbool = net.ReadNWBool() print(networkedbool) end ) --SERVER util.AddNetworkString( "activeAdmin" ) Player(2):SetNWBool("activeAdmin", true) print(Player(2):GetNWBool("activeAdmin")) local isPlayer2Admin = Player(2):GetNWBool("activeAdmin")) net.Start( "activeAdmin" ) net.WriteNWBool(isPlayer2Admin) net.Send( Player(2) ) --This makes no sense as you can just call LocalPlayer() in that client. But you can change what this is sent to. [/CODE] This way you are only sending a true/false instead of an entire entity's data tables[/QUOTE] You are severely uninformed on how this stuff works. I know you're trying to help and all, but you're just making things worse by confidently speaking about things you don't know much about.
Have you made sure your server is fully up to date, there's a chance your server could be on the version with the NWVars change.
Alright I have updated the server and I am going to see if it works now and it works! Thanks guys! Turns out I was just stupid and forget to update the server. And yes, client knows who Player(2) is...
Sorry, you need to Log In to post a reply to this thread.