Two Questions (chapter 5)
by Michael Rogers · in Torque Game Engine · 07/14/2005 (2:05 pm) · 5 replies
On p. 161, the author says that the function SplashScreenInputCtrl::OnInputEvent() closes the splash screen. But the code calls ShowMenuScreen(), which looks like it displays the screen, not gets rid of it. So my first question is,
1. What is SplashScreenInputCtrl::OnInputEvent() really doing?
Next, all the %this's kicking around in control/server/server.cs are confusing me. I thought I had this figured out -- that there was maybe one GameConnection object on the client, and that the server gets access to it. But that's not correct, as I found out using the debugger:
The client creates a GameConnection, with an ID of 1275 (p. 160) ; in GameConnection::OnClientEnterGame(%this) on p. 176, %this has a value of 1276.
2. How many GameConnection objects are there in a Game? I envisioned a GameConnection like a conduit, with two ends, so you'd apparently only need one, but that is not the case.
3. Related to question # 2, exactly what is the %this referred to in control/server/server.cs. Where is it coming from, which object is it associated with?
Thanks for enlightening a newbie.
Michael
1. What is SplashScreenInputCtrl::OnInputEvent() really doing?
Next, all the %this's kicking around in control/server/server.cs are confusing me. I thought I had this figured out -- that there was maybe one GameConnection object on the client, and that the server gets access to it. But that's not correct, as I found out using the debugger:
The client creates a GameConnection, with an ID of 1275 (p. 160) ; in GameConnection::OnClientEnterGame(%this) on p. 176, %this has a value of 1276.
2. How many GameConnection objects are there in a Game? I envisioned a GameConnection like a conduit, with two ends, so you'd apparently only need one, but that is not the case.
3. Related to question # 2, exactly what is the %this referred to in control/server/server.cs. Where is it coming from, which object is it associated with?
Thanks for enlightening a newbie.
Michael
About the author
#2
The %this in OnClientEnterGame is the ID for the servers GameConnection for the connected client.
2) Each client will have a GameConnection object. The server will have one for each connected client. In the chapter 5 example you're probably both the server and the client, which is why you'll be seeing two id's for the game connection.
3) What %this refers to depends upon what it is thats before the :: for example GameConnection::somefunction would have a %this as a reference to a specific clients GameConnection.
In the case of GUI's you might see TextEditCtrl::somefunction with %this been a reference to a specific instance of a TextEditCtrl control.
Alternativly if the item prior to the :: is a Name of an objcet rather than the name of a class, for example you might see MyTextControl::somefunction in which case %this would be a reference to a specific instance of whatever the MyTextControl is the name of. If MyTextControl is the name of a TextEditCtrl then %this would be a reference to the TextEdit control that has the name MyTextControl.
If you read through the torque script documents, theres a section about namespaces which explains this much better than I have above, which i feel may be a little confusing :P
07/14/2005 (2:54 pm)
1) The two ID's will be different because one will be the client side ID for the GameConnection, whilst the other will be the ID the server has assigned.The %this in OnClientEnterGame is the ID for the servers GameConnection for the connected client.
2) Each client will have a GameConnection object. The server will have one for each connected client. In the chapter 5 example you're probably both the server and the client, which is why you'll be seeing two id's for the game connection.
3) What %this refers to depends upon what it is thats before the :: for example GameConnection::somefunction would have a %this as a reference to a specific clients GameConnection.
In the case of GUI's you might see TextEditCtrl::somefunction with %this been a reference to a specific instance of a TextEditCtrl control.
Alternativly if the item prior to the :: is a Name of an objcet rather than the name of a class, for example you might see MyTextControl::somefunction in which case %this would be a reference to a specific instance of whatever the MyTextControl is the name of. If MyTextControl is the name of a TextEditCtrl then %this would be a reference to the TextEdit control that has the name MyTextControl.
If you read through the torque script documents, theres a section about namespaces which explains this much better than I have above, which i feel may be a little confusing :P
#3
I get it! GameConnections are like TCP connections in socket programming.
Thanks *very* much for the explanation, I'll be sure and give you credit when I'm explaining this to others...
Michael
07/14/2005 (3:12 pm)
Gary,I get it! GameConnections are like TCP connections in socket programming.
Thanks *very* much for the explanation, I'll be sure and give you credit when I'm explaining this to others...
Michael
#4
As a corollory to the above discussion, in GameConnection::CreatePlayer() (p. 177), the client field is assigned the value of %this -- but that's a reference to the *server*'s GameConnection object. So
1. Does this mean that the client field in the Player object is misnamed? Shouldn't it be called server?
2. Also, the code to create the player is all talking place on the server. How is that getting back to the client?
Thanks again for any assistance,
Michael
07/14/2005 (3:47 pm)
Gary, I hope you're still out there -- or if not, any other parties are invited to chime in... As a corollory to the above discussion, in GameConnection::CreatePlayer() (p. 177), the client field is assigned the value of %this -- but that's a reference to the *server*'s GameConnection object. So
1. Does this mean that the client field in the Player object is misnamed? Shouldn't it be called server?
2. Also, the code to create the player is all talking place on the server. How is that getting back to the client?
Thanks again for any assistance,
Michael
#5
1. The client field is *not* misnamed. All the code in GameConnection::CreatePlayer() is happening server-side, and %this, represents a particular GameConnection object, for a particular client. So, even though %this is an object on the server, it is referring to a particular client.
2. The statement a few lines down,
Have I got this right?
Michael
07/14/2005 (5:04 pm)
I'm going to try and answer my question, again. [Sorry about this, I'm just learning as I go.] If someone could corroborate/correct the following, I'd be greatful.1. The client field is *not* misnamed. All the code in GameConnection::CreatePlayer() is happening server-side, and %this, represents a particular GameConnection object, for a particular client. So, even though %this is an object on the server, it is referring to a particular client.
2. The statement a few lines down,
%this.setControlObject(%player);is establishing, on the server's GameConnection, that the client associated with it will be controlling the %player. At this point in the proceedings, the client really doesn't even know that the player exists, but will be told, presumably later on.
Have I got this right?
Michael
Torque Owner Michael Rogers