Game Development Community

GetControlObject within PlayGUI::onWake

by Justin Mosiman · in Torque Game Engine · 06/15/2006 (8:50 pm) · 9 replies

Hi,

I have a simple question that will hopefully have a simple answer: is there a way to get the control object from within PlayGUI::onWake?

What I want to do is check to see if x object has control, and if it does, do this, if y object has control, do that.

Thanks,
Justin

#1
06/15/2006 (9:44 pm)
You could simply use a clientCmd function set a client-side variable that your PlayGUI's onWake function can check to determine whether the control object is X or Y.


client:
function clientCmdNewControlObject(%what) { $currentControlObject = %what; }


server:
commandToClient(%client, 'NewControlObject', "X");
or
commandToClient(%client, 'NewControlObject', "Y");

Then in your PlayGUI::onWake you can simply:

if ($currentControlObject $= "X") DoXThing();
else if ($currentControlObject $= "Y") DoYThing();
#2
06/16/2006 (8:19 am)
I haven't tried out that piece of code yet, but it looks like it is a good amount of work just to get the control object. If I was able to get the client from within onWake, I would be able to get the control object. Is it not possible to get the client from onWake?
#3
06/16/2006 (9:00 am)
LocalClientConnection.getControlObject().
#4
06/16/2006 (9:43 am)
LocalClientConnection.getControlObject() worked great, thanks.
#5
06/17/2006 (2:00 am)
Bear in mind that LocalClientConnection is only valid for certain situations where the client is also the host. If you're developing a game that will connect to other servers or a dedicated server, then localClientConnection will not be valid.
#6
06/17/2006 (7:48 am)
Then what would you do if that's the situation? The clientCmd way?
#7
06/17/2006 (9:32 am)
Yeah, for multiplayer that's the way to go.
#8
06/17/2006 (11:56 am)
@gary - really ?
huh. i'll have to reconsider some code then.
thanks.
#9
06/17/2006 (12:19 pm)
@Orion:

LocalClientConnection only works on a listen-server, as it grabs the connection between the client and the server, and because there is no such connection when you're connecting to a dedicated, you won't get anything returned in such an enviorment.