Game Development Community

How do I pause a TGB game?

by Robert Carroll · in Torque Game Builder · 10/17/2009 (5:05 pm) · 6 replies

Hi, Im trying to find out how to pause my game I tried The pause mini-tut where you put the code at the end of game.cs and the .gui way. Is there a behavior that pauses it?

#1
10/17/2009 (6:46 pm)
if (!isObject(PauseBahavior))
{
   %template = new BehaviorTemplate(PauseBahavior);
   
   %template.friendlyName = "Pause Game";
   %template.behaviorType = "Scene";
   %template.description  = "Pause and unpause the game";

   %template.addBehaviorField(pauseKey, "The button to pause the game", Keybind, "keyboard P");
}

function PauseBahavior::onBehaviorAdd(%this)
{
   if (!isObject(moveMap))
      return;
      
   moveMap.bindCmd( getWord(%this.pauseKey, 0), getWord(%this.pauseKey, 1), "pauseGame();", "");

   $isPaused = false;
}

function pauseGame()
{
   if($isPaused)
   {   
      $timescale=1;     
   }
   else
   {
      $timescale=0;
   }
   
   $isPaused = !$isPaused;
}
Something like this? Copy it into a script file in your behaviors directory and add it to your player.

Give it a shot and let me know.
#2
10/17/2009 (8:19 pm)
Thank you Thank you Thank you, I stayed up half the night trying to get it to pause with the GUI, THNX!!!
#3
10/17/2009 (9:58 pm)
no prob bob.
#4
10/17/2009 (10:41 pm)
Do you know how to turn this into a Quitgame?
=============================================
if (!isObject(Quit))
{
%template = new BehaviorTemplate(Quit);

%template.friendlyName = "Quits The Game";
%template.behaviorType = "Scene";
%template.description = "Clicking on the object causes Quit";

}

function quit::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
}

function quit::onMouseDown(%this, %modifier, %worldPos)
{
%this.quit();
}

===========================================
Im a newbie :)
#5
10/18/2009 (1:06 am)
By using "%this.quit();" you are calling a function called "quit" in your behavior.
function quit::quit( %this )
{
}

Instead, you just want to call the system "quit();" function.
function quit::onMouseDown( %this, %modifier, %worldPos )
{
  quit();
}
#6
10/18/2009 (1:14 am)
Thnx