Client's global variable visible on server?
by James Litton · in RTS Starter Kit · 01/05/2006 (1:53 pm) · 3 replies
I was reading about this here:
www.garagegames.com/mg/forums/result.thread.php?qt=14233
In my project, the client has a profile window to show the stats for a selected unit.
Whenever the server detects a change for the "profiled unit", the server pushes an update to the client, so that the client can populate this profile window.
For now, I am only using one client and one server, both running on the same pc, from the one executable (short circuited).
Therefore in client/scripts/selection.cs onSelect:
I set a global $profiledUnit variable.
Then on the server, in server/scripts/core/gameConnection.cs:
I am trying to watch the attributes of the "$profiledUnit", to detect any changes.
But I just realized, this shouldn't work!!!
How would the server have access to the client's global $profiledUnit variable?
my print statements return the correct thing
On the client side, the profiled unit is 1546
...
On the server side, the profiled unit is 1546
Can the server see the client globals?
Is this a special case due to running on the same machine, short-circuited?
www.garagegames.com/mg/forums/result.thread.php?qt=14233
In my project, the client has a profile window to show the stats for a selected unit.
Whenever the server detects a change for the "profiled unit", the server pushes an update to the client, so that the client can populate this profile window.
For now, I am only using one client and one server, both running on the same pc, from the one executable (short circuited).
Therefore in client/scripts/selection.cs onSelect:
I set a global $profiledUnit variable.
function GuiRTSTSCtrl::selectObject(%this,%obj)
{
%this.addToSelection(%obj);
$profiledUnit = %obj;
echo("On the client side, the profiled unit is " @ $profiledUnit);
...Then on the server, in server/scripts/core/gameConnection.cs:
I am trying to watch the attributes of the "$profiledUnit", to detect any changes.
function RTSConnection::updateUnit(%this, %rtsUnit)
{
echo("On the server side, the profiled unit is " @ $profiledUnit);
%profiledObj = %rtsUnit.client.resolveObjectFromGhostIndex($profiledUnit.getGhostID());
if (%rtsUnit.getId() == %profiledObj){
...
...
%this.schedule(%profileUpdateMillis, "updateAgentProfile", %rtsUnit);
}But I just realized, this shouldn't work!!!
How would the server have access to the client's global $profiledUnit variable?
my print statements return the correct thing
On the client side, the profiled unit is 1546
...
On the server side, the profiled unit is 1546
Can the server see the client globals?
Is this a special case due to running on the same machine, short-circuited?
About the author
#2
Or to add an attribute to the client, so that the server could check a %client.profiledUnit variable.
I am actually using the RTS kit as a visualization for a simulation. The user wont really have control of any of the units. So basically, I only have observer clients, and the units should all be "NPC" and owned by the server. But, yes I should prepare for a multiple observer scenario.
I definately agree. Don't even try to write a game without a second machine to test on. Now I better go follow that advice.
01/05/2006 (3:38 pm)
Yeah, I think the right way to do this would be for the server to keep an array of profiled units, one for each client, and have the client call a serverCmdSetProfiledUnit to set it. Or to add an attribute to the client, so that the server could check a %client.profiledUnit variable.
I am actually using the RTS kit as a visualization for a simulation. The user wont really have control of any of the units. So basically, I only have observer clients, and the units should all be "NPC" and owned by the server. But, yes I should prepare for a multiple observer scenario.
I definately agree. Don't even try to write a game without a second machine to test on. Now I better go follow that advice.
#3
$sProfiledUnit
$cProfiledUnit
01/05/2006 (3:42 pm)
And I guess if I use the same globals I better be sure to use unique names on my server and client, like:$sProfiledUnit
$cProfiledUnit
Torque 3D Owner Stephen Zepp
Using this "feature" if you ever plan on being multi-player of any sort leads to all sorts of issues when you start testing your MP--code is now broken and extremely difficult to figure out why, etc...so I highly suggest you stay away from it! Make your game from the beginning as MP, and especially make sure you are testing properly with a non-attached client every step along the way.