Game Development Community

Open a gui by a trigger

by Jonathan Robinson · in Technical Issues · 05/22/2007 (12:55 pm) · 5 replies

I am new to torque, well 6 months in and haven't really sat down in front of the engine code! Basically I want to open a created gui from a trigger. So something along the lines of when a player enters a trigger it opens the relevant gui with the instructions. Basically I have a virtual world in which I want to inform the users about certain activities/facilities they can use in real life. They walk over to a computer and a gui pops up and says with these computers you can do this and this and this, blah blah blah.
Is a trigger the best way to achieve this and has anyone done it?
Thanks in advance.
Jon.

#1
05/22/2007 (1:16 pm)
Yep, that's the way to do it.
the overview goes something like this:
(all in script)
* make a new trigger datablock type - copy an existing one
* add an instance of the trigger to your mission.
* to that trigger instance, add a field like myMessage = "hey! this is the computer terminal!";
* override the OnEnter() method of the datablock to be something like this:
function myTrigger::onEnterTrigger(%this, %trigger, %player)
{
   %client =   %player.client;

   if(!isObject(%client))
   {
      //this is not a client controlled player, ignore it
      return;
   }

   commandToClient(%client, 'TriggerMessage', %trigger.myMessage);
}

* somewhere in the client script, add code like this:
function clientCommandTriggerMessage(%message)
{
   MessageBoxOK("title", %message);
}


.. the details may be off, but that's the overview.
#2
05/23/2007 (7:25 am)
Hi Orion.
Thanks for getting back to me. How exactly would I go about calling the gui then? I'm not completely clear on the script language.
Thanks.
Jon.
#3
05/23/2007 (12:11 pm)
I get the vague idea. This works similar to the exit function from the game apart from its called by the trigger instead if the bound Esc button. I'm going to give it ago later on.
However lets say I had a pre-designed GUI i had made via the GUI editor using GuiBrowserCtrl (web browser in a GUI) how would I go about calling this?
Thanks.
Jon.
#4
05/23/2007 (12:21 pm)
Hey Jon -

well there's a few different ways of opening a gui,
a search would probably turn up some useful stuff.

look at how the Netgraph or Chat hud are opened in the TGE FPS demo.

typically it's Canvas.pushGUI() if your GUI is indeed a whole GUI,
or you might prefer to make your GUI a normally-invisible part of playGui and do something like myControl.setVisible(true).
#5
05/23/2007 (3:35 pm)
Hi Orion
Thanks for the reply, I've had a look around and can't really find anything, to be honest its a shame there's no guide on this as its a nice function to have, but I guess it goes with anything new got to keep trying until you get it.
How would I go about adding this to the client script and where? The trigger I've played around with is the temple of doom one which writes to the console, and is all done server side! Would I simply create another trigger.cs file at the client side?
Thanks
Jon.