Game Development Community

script problem

by Desmond Fletcher · in Torque Game Engine · 03/25/2002 (3:38 pm) · 6 replies

I'm having a bit of a problem with this script to call a gui via toggle. The gui toggles on ok, but will not toggle off and the mouse is inactivated for everything except the gui. Any ideas?

function toggleMetricsMenu(%val)
{
if( !isObject(MetricsMenuGui))
{
//Canvas.repaint();
exec("./MetricsMenuGui.gui");

if (Canvas.getContent() == MetricsMenu.getId())
MetricsMenu.close();
else
MetricsMenu.open();
}

if(%val)
{
if(!MetricsMenu.open)
{
Canvas.pushDialog(MetricsMenu);
MetricsMenu.open = true;
}
else
{
Canvas.popDialog(MetricsMenu);
MetricsMenu.open = false;
}
}
}

function MetricsMenu::open(%this)
{
if(%this.isVisible())
return;
%this.setVisible(true);
}

function MetricsMenu::close(%this)
{
if(!%this.isVisible())
return;

%this.setVisible(false);
}

GlobalActionMap.bind(keyboard, "f5", toggleMetricsMenu);

#1
03/25/2002 (4:55 pm)
Change this part

if(%val) 
{ 
  if(!MetricsMenu.open) 
  { 
    Canvas.pushDialog(MetricsMenu); 
    MetricsMenu.open = true; 
  } 
  else 
  { 
    Canvas.popDialog(MetricsMenu); 
    MetricsMenu.open = false; 
  } 
}

to this

if(%val) 
{ 
  if(!MetricsMenu.isAwake()) 
  { 
    Canvas.pushDialog(MetricsMenu); 
    MetricsMenu.open = true; 
  } 
  else 
  { 
    Canvas.popDialog(MetricsMenu); 
    MetricsMenu.open = false; 
  } 
}


MetricsMenu.open does not return any value to your if statement.
#2
03/25/2002 (7:25 pm)
That didn't get it--the menu still pops up and I can activate stuff from the menu, but can't toggle the menu down.
#3
03/25/2002 (8:04 pm)
First thing to try then.

Put an echo in that toggle function right at the start and attempt to use the keybind.

We need to determine if the binding is actually working
#4
03/25/2002 (8:19 pm)
It gets thru toggleopen

if(%val)
{
if(!MetricsMenu.isAwake())
{
MessageBoxOK("Toggleopen");
Canvas.pushDialog(MetricsMenu);
MetricsMenu.open = true;
}
else
{
MessageBoxOK("Toggleclose");
Canvas.popDialog(MetricsMenu);
MetricsMenu.open = false;
}
}

But I can't select the ok button with the mouse. I can still toggle the radio buttons on the gui.
#5
03/25/2002 (8:32 pm)
function toggleMetricsMenu(%val)
{
echo(%val);

I added that to the function and get this in the console by pressing the F5 key only once:

1
Loading compiled script common/metrics/MetricsMenuGui.gui
0
Loading compiled script common/metrics/MetricsMenuGui.gui
keyboard0 input device unacquired.

So it would seem that it's not unloading the gui ??
#6
03/25/2002 (10:06 pm)
Hmmm
Why are you execing the gui file each time you load the gui? I cant imagine why you would want to do this. This is how I would code it.

in init.cs put the exec with the other gui loading
exec("./MetricsMenuGui.gui");

The toggle function
function toggleMetricsMenu(%val) 
{ 
   if(%val)
   {
   	if (MetricsMenu.isAwake())
   	{
     	   Canvas.popDialog(MetricsMenu);
	}
   	else
   	{
     	   Canvas.pushDialog(MetricsMenu);
           MetricsMenu.setVisible(true);
	}
   }
}

GlobalActionMap.bind(keyboard, "f5", toggleMetricsMenu);

That is how I toggle my guis and they work.