Trigger that displays and removes gui
by Timothy Downs · in Torque Game Engine · 07/21/2004 (4:56 pm) · 5 replies
I am a Digital Media Design Student preparing for my Senior year. In this senior year I have a final thesis that I need do, which is a big major project involving a statement I want to make with my art. My statement is a virtual portfolio using Torque.
I want to create a trigger that when a player enters it they bring up a gui. And when the leave it the gui is removed from the screen. Any help would be greatly appreciated. Thanks.
I want to create a trigger that when a player enters it they bring up a gui. And when the leave it the gui is removed from the screen. Any help would be greatly appreciated. Thanks.
About the author
#2
1. onEnterTrigger() will happen on the *server*, not the client,
so you'll need to commandToClient('openSomeGui');
note that if you're running both the server & client in one instance, which is typically the most common way folks develop, i believe, this method *will* work, but you'll be sad if you ever try it across a network.
see this thread for more info.
2. exec'ing test.gui is not the right way to open a gui.
look at how the options dialog is opened. you're looking for things like Canvas.pushDialog().
04/06/2006 (6:24 pm)
Couple things going on for you here, Sventhors -1. onEnterTrigger() will happen on the *server*, not the client,
so you'll need to commandToClient('openSomeGui');
note that if you're running both the server & client in one instance, which is typically the most common way folks develop, i believe, this method *will* work, but you'll be sad if you ever try it across a network.
see this thread for more info.
2. exec'ing test.gui is not the right way to open a gui.
look at how the options dialog is opened. you're looking for things like Canvas.pushDialog().
#3
First I made guiText (or can use BitmapGUI) in f10.
named it yeah.gui
Turned off Visible
Saved playerGui.gui
//
I checked it in Console(to see if it responds) by typing yeah.Visible = 1;
and turned it off yeah.Visible = 0;
my triggers.cs script
Made a trigger named awesome. Save. There it is.
-------------
It be great someone could explain how to trigger Canvas.pushDialog(). or how pop works.
------
Any additional comments will be great.
04/09/2006 (2:42 pm)
I got a another way to work for this. Yeah. I could not figure out how Canvas.pushDialog(). works. I have been trying it for two days and no luck. This is how I did it by triggering text.First I made guiText (or can use BitmapGUI) in f10.
named it yeah.gui
Turned off Visible
Saved playerGui.gui
//
I checked it in Console(to see if it responds) by typing yeah.Visible = 1;
and turned it off yeah.Visible = 0;
my triggers.cs script
datablock TriggerData(awesome)
{
// The period is value is used to control how often the console
// onTriggerTick callback is called while there are any objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
};
//-----------------------------------------------------------------------------
function awesome::onEnterTrigger(%this,%trigger,%obj)
{
// This method is called whenever an object enters the %trigger
// area, the object is passed as %obj. The default onEnterTrigger
// method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
// every object (whatever it's type) in the same group as the trigger.
Parent::onEnterTrigger(%this,%trigger,%obj);
//echo("TEXT-RRRR");
//Canvas.popDialog(NameOfGUI); //Close it the Gui
//Canvas.pushDialog(awesome);
echo("TEXT!!!!!!!!!!!!!!!!!!!!!!!!!!!");
yeah.Visible = 1;
}
function awesome::onLeaveTrigger(%this,%trigger,%obj)
{
Parent::onLeaveTrigger(%this,%trigger,%obj);
// echo("Need more beer got to Leave!");
yeah.Visible = 0;
}
function awesome::onTickTrigger(%this,%trigger)
{
Parent::onTickTrigger(%this,%trigger);
}Made a trigger named awesome. Save. There it is.
-------------
It be great someone could explain how to trigger Canvas.pushDialog(). or how pop works.
------
Any additional comments will be great.
#4
First I made guiText (or can use BitmapGUI) in f10.
named it yeah.gui
Turned off Visible
Saved playerGui.gui
//
I checked it in Console(to see if it responds) by typing yeah.Visible = 1;
and turned it off yeah.Visible = 0;
my triggers.cs script
Made a trigger named awesome. Save. There it is.
-------------
It be great someone could explain how to trigger Canvas.pushDialog(). or how pop works.
------
Any additional comments will be great.
04/09/2006 (3:07 pm)
I got a another way to work for this. Yeah. I could not figure out how Canvas.pushDialog(). works. I have been trying it for two days and no luck. This is how I did it by triggering text.First I made guiText (or can use BitmapGUI) in f10.
named it yeah.gui
Turned off Visible
Saved playerGui.gui
//
I checked it in Console(to see if it responds) by typing yeah.Visible = 1;
and turned it off yeah.Visible = 0;
my triggers.cs script
datablock TriggerData(awesome)
{
// The period is value is used to control how often the console
// onTriggerTick callback is called while there are any objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
};
//-----------------------------------------------------------------------------
function awesome::onEnterTrigger(%this,%trigger,%obj)
{
// This method is called whenever an object enters the %trigger
// area, the object is passed as %obj. The default onEnterTrigger
// method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
// every object (whatever it's type) in the same group as the trigger.
Parent::onEnterTrigger(%this,%trigger,%obj);
//echo("TEXT-RRRR");
//Canvas.popDialog(NameOfGUI); //Close it the Gui
//Canvas.pushDialog(awesome);
echo("TEXT!!!!!!!!!!!!!!!!!!!!!!!!!!!");
yeah.Visible = 1;
}
function awesome::onLeaveTrigger(%this,%trigger,%obj)
{
Parent::onLeaveTrigger(%this,%trigger,%obj);
// echo("Need more beer got to Leave!");
yeah.Visible = 0;
}
function awesome::onTickTrigger(%this,%trigger)
{
Parent::onTickTrigger(%this,%trigger);
}Made a trigger named awesome. Save. There it is.
-------------
It be great someone could explain how to trigger Canvas.pushDialog(). or how pop works.
------
Any additional comments will be great.
#5
GUI elements are part of the client, thusly you need a function in your client scripts like this:
And then change your onEnter and onLeave Trigger functions to have this in them
I actually haven't done much GUI programming, but I'm assuming this is how it works just going of knowledge of the client/server setup.
04/09/2006 (3:58 pm)
Try what you are doing running a dedicated server and connecting to it. I doubt it will work, and it's only working now because your client and server are running together.GUI elements are part of the client, thusly you need a function in your client scripts like this:
function clientCmdToggleGUI(%val){
if(%val){
Canvas.popDialog(NameofGUI);
Canvas.pushDialog(awesome);
}
else{
Canvas.popDialog(awesome);
Canvas.pushDialog(NameofGUI);
}
}And then change your onEnter and onLeave Trigger functions to have this in them
if(%obj.client) CommandToClient(%obj.client, 'ToggleGUI', 1); //And if(%obj.client) CommandToClient(%obj.client, 'ToggleGUI', 0); //Respectively
I actually haven't done much GUI programming, but I'm assuming this is how it works just going of knowledge of the client/server setup.
Torque Owner Sventhors
But havent been succesful. But I get it to load up in f11. and I get and error
that says
cannont change namessapce parent linkage for Test From TriggerData to GuiTextCtrl.
But when I click out from f11 then GUI shows. :)
This is this scriot I used.
datablock TriggerData(Test) { // The period is value is used to control how often the console // onTriggerTick callback is called while there are any objects // in the trigger. The default value is 100 MS. tickPeriodMS = 100; }; //----------------------------------------------------------------------------- function Test::onEnterTrigger(%this,%trigger,%obj) { // This method is called whenever an object enters the %trigger // area, the object is passed as %obj. The default onEnterTrigger // method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on // every object (whatever it's type) in the same group as the trigger. Parent::onEnterTrigger(%this,%trigger,%obj); exec("starter.fps/client/ui/test.gui"); } function Test::onLeaveTrigger(%this,%trigger,%obj) { Parent::onLeaveTrigger(%this,%trigger,%obj); } function Test::onTickTrigger(%this,%trigger) { Parent::onTickTrigger(%this,%trigger); }Im hoping some on here can help us out thanks:)