Author Topic: Game not Unpausing, possible bug?  (Read 709 times)

Chrille

  • Posts: 726
    • Chrille worked on a game that was nominated for an AGS Award!
      Chrille worked on a game that won an AGS Award!
Game not Unpausing, possible bug?
« on: 15 Jul 2010, 16:49 »
I ran into an issue where my game wouldn't accept/run the UnPauseGame(); function. It happens if PauseGame(); is run while the game is already paused, it seems to break UnPauseGame();.

I fixed it by only letting the game run the function if the game isn't already paused. Has anyone else encountered this or is it something else in my game causing this problem?
GASPOP software
http://www.gaspop.com

Ryan Timothy B

  • Posts: 2,834
    • I can help with play testing
    • I can help with scripting
    • Ryan Timothy B worked on a game that was nominated for an AGS Award!
Re: Game not Unpausing, possible bug?
« Reply #1 on: 15 Jul 2010, 19:04 »
Well if you have PauseGame() running in the repeatedly_execute_always with no restrictions along with UnPauseGame() just before or after, the game would always be paused.

I have the space bar pause the game in the one I'm currently working on, and this is the code I used:

Code: [Select]
bool spaceIsHeld;
Code: [Select]
function repeatedly_execute_always()
{  
  if (!spaceIsHeld && IsKeyPressed(eKeySpace))
  {
    if (!IsGamePaused())
    {
      PauseGame();
      SetSkipSpeech(2);    //this is to prevent the glitch with the mouse click skipping text during pausegame
    }
    else
    {
      UnPauseGame();
      SetSkipSpeech(0);    //this is to prevent the glitch with the mouse click skipping text during pausegame
    }
    spaceIsHeld=true;
  }
  else if (!IsKeyPressed(eKeySpace)) spaceIsHeld=false;
}

The reason I put both pause and unpause in the repeatedly_execute_always, is since you may want to pause the game during blocking moments like dialog, etc.  I also needed that spaceIsHeld boolean to prevent it from pausing and unpausing each game cycle until you've released the space bar.  This way it will act like on key press.

Edit: tweaked the code slightly better
« Last Edit: 15 Jul 2010, 19:14 by Ryan Timothy »

hedgefield

  • Posts: 619
  • Oh snap!
    • I can help with play testing
    • I can help with translating
    • I can help with voice acting
Re: Game not Unpausing, possible bug?
« Reply #2 on: 15 Jul 2010, 22:14 »
Maybe this module can help?

Chrille

  • Posts: 726
    • Chrille worked on a game that was nominated for an AGS Award!
      Chrille worked on a game that won an AGS Award!
Re: Game not Unpausing, possible bug?
« Reply #3 on: 15 Jul 2010, 22:26 »
Ok. Not quite my problem though. Just wanted to report what might be a bug because I really don't see what could explain this.

I made a function that, depending on whether a parameter is set to open or close. It opens or closes a gui window. Like this:

function openGUI (int action) {
 if (action == open) {
   gui.Visible = true;
   bla bla bla;
   PauseGame();
 }
 else if (action == close) {
   gui.Visible = false;
   bla bla bla;
   urk urk urk;
   UnPauseGame();
 }
}

The ONLY time the problem where the game can't be unpaused occurs is if this function is called with the open parameter while the gui is already open and the game paused. I know the function runs because it executes everything else within the close action. It's just that UnPauseGame(); has no effect. PauseGame(); isn't run from any other function or repeatedly execute.

GASPOP software
http://www.gaspop.com

Ryan Timothy B

  • Posts: 2,834
    • I can help with play testing
    • I can help with scripting
    • Ryan Timothy B worked on a game that was nominated for an AGS Award!
Re: Game not Unpausing, possible bug?
« Reply #4 on: 15 Jul 2010, 22:56 »
I see what you mean.  I used this to see if this is what you were talking about:
Code: [Select]
function repeatedly_execute()
{
  if (Game.DoOnceOnly("TESTING"))
  {
    PauseGame();
    PauseGame();
    UnPauseGame();
  }
}
But if you do two UnPausegame()'s back to back, it would start working again.


I'm not sure if you could call this a glitch since it IS doing what you're telling it to do.  I could possibly see a purpose for having it not unpause in moments where you may have called pause twice or more.
It's a pesky feature. :P


In your scenario, the only thing to stop it from calling PauseGame again is to do this before calling PauseGame:
Code: [Select]
 if (!IsGamePaused()) PauseGame();
Edit: Now that I've read it again, it seems you already had the solution:
Quote
I fixed it by only letting the game run the function if the game isn't already paused.
« Last Edit: 15 Jul 2010, 23:02 by Ryan Timothy »

Pumaman

  • Creator of AGS
  • Posts: 10,499
  • I sense danger.
    • Lifetime Achievement Award Winner
Re: Game not Unpausing, possible bug?
« Reply #5 on: 20 Jul 2010, 22:21 »
PauseGame counts the number of times it is called, and you have to call UnPauseGame the same number of times before the game starts running again. This is by design.