How to get gameconnection (client) from script?
by Dusty Monk · in Technical Issues · 07/09/2006 (12:00 am) · 6 replies
What's the best way to get to the client (GameConnection) from an arbitrary script function? I'm trying to write a function that manipulates both the camera and the player -- both of which hang off what is typically called 'client', ie the game connection. But in every instance of code I can find, the gameconnection is either passed in (as in a servercmd), or it is a function of the object itself, and so gets passed in by default (as in GameConnection::CreatePlayer)
I've been digging through forum posts, sample code, & reference articles all night, but can't seem to find any code anywhere that uses a GameConnection that isn't passed in by parameter.
Thanks tons,
Dusty
ps - my function wants to put the camera in orbitmode about the player. I get how orbitmode works, and it's exactly what I need. I just can't figure out how to get handles on the camera and the player within my function. If you know of a better way to go where I want to go without going through GameConnection, that's helpful too. Thanks. :)
I've been digging through forum posts, sample code, & reference articles all night, but can't seem to find any code anywhere that uses a GameConnection that isn't passed in by parameter.
Thanks tons,
Dusty
ps - my function wants to put the camera in orbitmode about the player. I get how orbitmode works, and it's exactly what I need. I just can't figure out how to get handles on the camera and the player within my function. If you know of a better way to go where I want to go without going through GameConnection, that's helpful too. Thanks. :)
About the author
Dusty Monk is founder and president of Windstorm Studios, an independant game studio. Formerly a sr. programmer at Ensemble Studios, Dusty has worked on AAA titles such as Age of Empires II & III, and Halo Wars.
#2
What I was looking for was in a function that is *not* defined either as a member of GameConnection itself or that didn't have a gameconnection passed into it, what was the best way to find the GameConnection for this client. Digging through some other code, it looks like 'ServerConnection' might be a global variable that is what I need.
I'm assuming that 'ServerConnection' is this client's game connection to the server. Which is exactly what I need. I'm going to try that and see if that works.
As an aside, it turns out setOrbitMode isn't what I really want anyway. In order for setOrbitMode to work, the camera has to be the control object. I really want the player to remain as the control object, but allow the user to rotate the camera about the player as he moves. So I may have to end up implementing the Advanced Camera stuff anyway.
D.
07/09/2006 (9:19 am)
Hey Mike. Thanks for the reply. However, that code snippet has the same problem as the others I looked at -- that is, the code is defined within a method of the GameConnection object, so you already have access to the GameConnection through the %this parameter that is automatically passed in.What I was looking for was in a function that is *not* defined either as a member of GameConnection itself or that didn't have a gameconnection passed into it, what was the best way to find the GameConnection for this client. Digging through some other code, it looks like 'ServerConnection' might be a global variable that is what I need.
I'm assuming that 'ServerConnection' is this client's game connection to the server. Which is exactly what I need. I'm going to try that and see if that works.
As an aside, it turns out setOrbitMode isn't what I really want anyway. In order for setOrbitMode to work, the camera has to be the control object. I really want the player to remain as the control object, but allow the user to rotate the camera about the player as he moves. So I may have to end up implementing the Advanced Camera stuff anyway.
D.
#3
07/09/2006 (10:13 am)
Ok. I'm not that good at torque programming yet. Hope you get it fixed up the way you need it. :)
#4
it's important to remember the server/client nature of torque.
Most of the functions which manipulate an object of type 'client' are server-side, and since there's potentially many many clients, the server doesn't really retain a notion of "the" client.
So one way you could do it is to use commandToServer().
For example if pressing a certain key triggers the orbit cam business, you could bind that key client-side to a commandToServer(), which on the server-side would then have the %client object.
Another possibility is if you've already got the %player object server-side, just use the client field of that object.
ie "%thePlayer.client".
07/09/2006 (11:04 am)
Dale -it's important to remember the server/client nature of torque.
Most of the functions which manipulate an object of type 'client' are server-side, and since there's potentially many many clients, the server doesn't really retain a notion of "the" client.
So one way you could do it is to use commandToServer().
For example if pressing a certain key triggers the orbit cam business, you could bind that key client-side to a commandToServer(), which on the server-side would then have the %client object.
Another possibility is if you've already got the %player object server-side, just use the client field of that object.
ie "%thePlayer.client".
#5
I did get the code working through a servercmd, just as you suggested, but I'm not really happy with that. I'm trying to reduce the number of things that server has to worry about. And it seems like syncing every client's camera in the game is overhead it shouldn't have to deal with.
On the other hand, I don't really know how Torque's server deals with client discovery information yet, so maybe it needs to know the current state of each client's camera in order to resolve the things that client knows about.
D.
07/10/2006 (4:33 am)
Hey Orion. You're absolutely right, and I probably wasn't clear when I was saying I was looking specifically for 'the client'. As the code I was trying to write was strictly camera manipulation, which seems like it could be strictly client side, then I was trying to find examples of client side code where I could get a handle to the single game connection that linked us back to the server. I did get the code working through a servercmd, just as you suggested, but I'm not really happy with that. I'm trying to reduce the number of things that server has to worry about. And it seems like syncing every client's camera in the game is overhead it shouldn't have to deal with.
On the other hand, I don't really know how Torque's server deals with client discovery information yet, so maybe it needs to know the current state of each client's camera in order to resolve the things that client knows about.
D.
#6
yeah,
it's a bit weird and also frustrating that the server is being loaded down with dealing with everyone's camera.
i think the reasoning there is to discourage client-side cheating such as hacking your client to allow your camera to fly thru walls or whatever.
i'm sure you could get it done purely client-side, but i suspect it'd be a bit of work.
07/10/2006 (8:26 am)
Hi Dale,yeah,
it's a bit weird and also frustrating that the server is being loaded down with dealing with everyone's camera.
i think the reasoning there is to discourage client-side cheating such as hacking your client to allow your camera to fly thru walls or whatever.
i'm sure you could get it done purely client-side, but i suspect it'd be a bit of work.
Torque Owner Mike Rowley
Mike Rowley
I don't know if this is what you are looking for, but in "starter.racing/server/scripts/game.cs" in the gameStart function is this code:
It's supposed to make the camera orbit around the car at the beginning of the game.
Hope this helps you a bit.