I haven't written any code yet that works but is there a way of receiving a boolean variable from server side and then using it in action on the client side.
e.g/ I'm trying to make it so when an entity collides with another it sets a variable to true and then I need the client side to recognise this change of false to true and then write text on an entity's surface.
If any additional info is needed i'll be happy to provide and any help is greatly appreciated, thanks!
Its one of the most used things in addon, because otherwise most stuff wouldnt work. Its called networking and CODEBLUE made a great tutorial about it
https://www.youtube.com/watch?v=ODlGyS6lR1M
I've seen that but keep having problems trying to make it so the server sends a variable to the client.
All I want to do is have the server set a variable to true or send a true value to the client and then the client run an if statement and if it is true then run an operation.
well the if statement is clientside only. also to change a variable to true you dont have to pass it from the server to the client. You could also use a network function that when it runs (means when the server sends that network t othe client) inside that function the variable gets changed to true. So there has to be no variable passing. The client changes it themselfs once they get the network message
I think I understand, is that with the net.WriteBool , net.WriteInt , etc?
net.WriteBool and net.WriteInt is for transfering Booleans or numbers themself. Which you could do. But since your just wanting to change a variable once a certain event happens, i would use a normal net.send to send the netmessage to the client. Once the netmessage has been recived on the client, it runs the code you have inside and change a variable to true if still necessary.
I mean, it depends on what you do. Sometimes you need writebool or writeint or just normal net.send
Here's an example of a simple networked "boolean toggle"(not writing anything)
-- Server
util.AddNetworkString("toggle_something")
function ToggleSomething(ply)
if not IsValid(ply) then return false end -- indication of a failure
net.Start("toggle_something")
net.Send(ply)
return true -- indication of success
end
-- Client
local something = false
function ToggleSomething()
something = not something
end
net.Receive("toggle_something", ToggleSomething)
or if you don't want to rely on a "toggle" since in some cases it might be inconsistent, you could...
-- Server
util.AddNetworkString("set_something")
function SetSomething(ply, bool)
if not (IsValid(ply) and isbool(bool)) then return false end -- indication off ailure
net.Start("set_something")
net.WriteBool(bool)
net.Send(ply)
return true -- indication of success
end
-- Client
local something = false
function SetSomething(bool)
if not isbool(bool) then return end
something = bool
end
net.Receive("set_something", function()
SetSomething(net.ReadBool())
end)
Oh I get what you mean, thanks for the help !
Sorry, you need to Log In to post a reply to this thread.