Net Library - Question / Help

Hello Facepunch,

While I’m currently at college, I’m unable to test this code out myself. I’m just practicing on something very basic. When a player joins the game, it’ll assign a varible on the player and send a message to the client.

Like so:

// Server

function GM:PlayerSpawn( ply )
  ply.inLobby = true
  net.Send( ply )

But the question I have is, when I store a variable on the player ‘ply.inLobby’ if I wanted to use that clientside would I have to ‘WriteBool()’ to the client or can I just do ‘print( LocalPlayer().inLobby )’.

I appreciate your help Facepunch, hopefully someone can help. Thank you!

The client wouldn’t know of that variable because it’s on the server, not the client. Why would you need to send the value anyways? The client would already know it’s in the lobby because you sent a net message for it.

you could do this on the client:

net.Receive("Client_openLobby", function()
   LocalPlayer().inLobby = true

So what you’re saying is essentially there is no need to send the variable because the client already knows he has a variable assigned to him?

You’re not understanding. There is no need to send a variable telling the client they are in a lobby in a message that is telling them they are in a lobby.

Ah right, it’d make a lot more sense actually to do this clientside due to specific clients.


[editline]11th January 2017[/editline]

Yeah! But to do that, on the server before I send the message don’t I need to WriteBool since the variable assigned to the player is a bool?

There is a little more then that. The aim was to assign the variable on the player *when the player spawns * which then will be sent to the client ( i.e a menu pops up, you click a button, it’ll make the varible false )