Game not Unpausing, possible bug?

Started by Chrille, Thu 15/07/2010 16:49:12

Previous topic - Next topic

Chrille

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

#1
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: ags

bool spaceIsHeld;

Code: ags

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


Chrille

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

#4
I see what you mean.  I used this to see if this is what you were talking about:
Code: ags

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: ags

  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.

Pumaman

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.

SMF spam blocked by CleanTalk