How to get the value from a server variable ?
by Michael Schaumburg · in Torque Game Engine · 03/18/2005 (9:26 am) · 7 replies
I have a team implementation, where in the starting GUI, you decide wether or not to make
a team play. I have a variable set in common\client\prefs which is called $pref::Server::TeamPlay = "0";
If you start a team play the variable goes to "1".
Now if I host a multiplayer team game, on the server, this variable goes to "1". If a client joins this
game, I need to get the information, if the server starts a team play. So how can I get the value,
before the client start the game to start a team play or not ??
I tried it in GameConnection::OnConnect but it doesn't work. Maybe I am thinking wrong.
a team play. I have a variable set in common\client\prefs which is called $pref::Server::TeamPlay = "0";
If you start a team play the variable goes to "1".
Now if I host a multiplayer team game, on the server, this variable goes to "1". If a client joins this
game, I need to get the information, if the server starts a team play. So how can I get the value,
before the client start the game to start a team play or not ??
I tried it in GameConnection::OnConnect but it doesn't work. Maybe I am thinking wrong.
#2
No other way, so I must try to get it work......
03/18/2005 (12:53 pm)
It is complicated like this ??? I can't believe, only to read a value the server initiated !! No other way, so I must try to get it work......
#3
03/18/2005 (1:03 pm)
It's not that it's complicated, it's that by definition you do not normally want clients to have easy access to server variables. That would open you up to an amazing assortment of hacks and cheats that would destroy any game. Due to that, you need to broadcast intentionally variables that you want the client to know about, in a very controlled manner.
#4
serverCmdSetServer... should be clientCmdSetServer....
Now it's fixed, so I look like a moron. There was an error, but it's fixed now, so you can completely ignore my post :)
You can see examples of other clientCmd functions inside client.cs (somewhere in the client subfolder) as well as some other places in the scripts.
03/18/2005 (1:16 pm)
Just a note.... in Stephen's code there is (at least) one small error.serverCmdSetServer... should be clientCmdSetServer....
Now it's fixed, so I look like a moron. There was an error, but it's fixed now, so you can completely ignore my post :)
You can see examples of other clientCmd functions inside client.cs (somewhere in the client subfolder) as well as some other places in the scripts.
#5
My original post fixed.
03/18/2005 (1:20 pm)
Thanks for the correction--I always get those confused...some type of mental block or something, and I use the commands all the time :(My original post fixed.
#6
03/19/2005 (6:26 am)
Stephen, I don't know what Alan means, but it works like you say, with no corrections....
#7
03/19/2005 (7:21 am)
Because I corrected the code myself after Alan brought it up! What is above is the way it should be (now, it wasn't).
Torque 3D Owner Stephen Zepp
commandToClient(%client, 'SetServerStateVariables', "TeamPlay", $pref::Server::TeamPlay);
on the server, and in the client:
clientCmdSetServerStateVariables(%variableToSet, %value)
{
...parse out which variable to set
...set the value client side
}
Another option would be to have a c++ class that contains the server state of the variables in source code, and then ghost that object to the client. The client would then automatically be updated with the state changes as they occur, or during their initial update.