Game Development Community

Debug Panel Toggle Key

by Steve1982 · in Torque Game Builder · 03/03/2009 (12:16 am) · 6 replies

I'm trying to setup the F1 key to toggle the debug panel off and on. Here is my code:

function BallClass::onLevelLoaded(%this, %scenegraph)
{
%this.setSpeed();
%this.setLinearVelocityX(%this.speed);
%this.setLinearVelocityY(%this.speed);

GlobalActionMap.bind(keyboard, "F1", toggleDebugPanel);
}
function toggleDebugPanel(%this, %scenegraph )
{
if %scenegraph.getDebug == true
%scenegraph.setDebugOff(0); <==parse error
else
%scenegraph.setDebugOn(0);
}


I'm using Torsion and it gives a parse error. Any help is always appreciated.

#1
03/03/2009 (3:45 am)
http://tdn.garagegames.com/wiki/TorqueScript#Control_Statements
#2
03/03/2009 (3:46 am)
 
#3
03/03/2009 (5:32 am)
Your if statements need to be setup with Parenthesis and curly brackets like this

if ( %blaaahh == %blahblam)
  {
    doSomethingCool();
  }
else
  {
    notCool();

  }
#4
03/04/2009 (12:06 am)
I made the changes you suggested and it compiles now but I'm not getting the results I expected. When the program runs, the debug banner is always displayed. Pressing F1 has no effect. My code is:

function BallClass::onLevelLoaded(%this, %scenegraph)
{
%this.setSpeed();
%this.setLinearVelocityX(%this.speed);
%this.setLinearVelocityY(%this.speed);

GlobalActionMap.bind(keyboard, "F1", toggleDebugPanel(%scenegraph));
}

function toggleDebugPanel(%scenegraph)
{
if (%scenegraph.getDebug == true)
{
%scenegraph.setDebugOff(0);
}
else
{
%scenegraph.setDebugOn(0);
}
}
Thanks again for your help.
#5
03/04/2009 (12:48 am)
Steve, try this:

GlobalActionMap.bindCmd(keyboard, "F1", "toggleDebugPanel(" @ %scenegraph @ ");", "");

function toggleDebugPanel(%sceneGraph)
{
    if (!%sceneGraph.getDebugOn(0))
    {
        %sceneGraph.setDebugOn(0);
    }
    else
    {
        %sceneGraph.setDebugOff(0);
    }
}

For future reference, you should put your code inside [code ][/code ] tags to make them easier to read (remove the spaces in the tags to get them to work).

Edit: How odd, weird line breaks where there shouldn't be!
#6
03/04/2009 (1:13 am)
That worked perfectly. Thank you Phillip.