Accessing the server connection from the client
While writing gameplay code for the client, it is important to be able to access the GameConnection
class instance to the server. In this recipe, we will learn how to access the server connection class on the client.
How to do it...
In Torque 3D there are three different locations that the connection from the client to the server may be made. In each case the code looks as follows:
%conn = new GameConnection(ServerConnection);
In this code, the GameConnection
instance is given a name of ServerConnection
. It is through this name that we may work with the connection to the server on the client. For example, to access the object currently being controlled by the client, which is typically the Player
class, we may do the following:
%object = ServerConnection.getControlObject(); if(%object.isInNamespaceHierarchy("Player")) { // Do something with the player instance } else { // Work with another control object class, such as // a vehicle }