PauseGame on GUI

Started by AdamM, Sun 04/02/2007 04:04:19

Previous topic - Next topic

AdamM

So I've scripted so that when a player presses Escape, it calls PauseGame and brings up a menu GUI (IF the menu GUI isn't visible in the first place, which means if it is the Escape key will hide it and call UnPauseGame).

This all looks fine and dandy on paper, but as soon as I stuck PauseGame and UnPauseGame into my script, the Escape key doesn't get rid of the GUI. Why is this? PauseGame shouldn't stop on_key_press, should it? Is it something to do with the button animation I'm running in the GUI at the same time?

Code: ags
Ã,  if (keycode==27)
 {
if (gMenu.Visible==true) 
{
gMenu.Visible=false; UnPauseGame();
} 
else {
gMenu.Visible=true; PauseGame(); Animation.Animate(25, 0, 10, eRepeat);
}
}

Khris

I've cleaned up that code a bit:
Code: ags
  if (keycode==27) {
    if (gMenu.Visible==true) {
      gMenu.Visible=false;
      UnPauseGame();
    }
    else {
      gMenu.Visible=true;
      PauseGame();
      Animation.Animate(25, 0, 10, eRepeat);
    }
  }

Move the code up before the "if (IsGamePaused()) keycode=0;" line and it will work.

Ashen

Quote from: AdamM on Sun 04/02/2007 04:04:19
PauseGame shouldn't stop on_key_press, should it?

As Khris says, there's an if(IsGamePaused) condition in on_key_press that nullifys the keycodes - so yes, pausing the game SHOULD stop on_key_press. The solution is simple (again, as Khris has said), just rearrange your code so the Esc stuff is run first.

However, if you want the GUI to pause the game, why not just use a 'Popup Modal' one, which does that by default?
I know what you're thinking ... Don't think that.

AdamM

#3
Aha, I didn't notice that. Thanks, I'll paste the code before it.

Er, what do you mean "cleaned up the code", KhrisMUC? Doesn't look like you've changed anything to me.

Ashen, I thought my GUI was a popup modal one (and I actually expected you to say that, because I searched the forums and you've said that before in response to GUI and PauseGame queries :)). But the thing is the game didn't pause when I pressed Escape - I could still see the character.[EGO] idle animations running in the background. When I stuck PauseGame in there, they stopped.

Khris

I didn't change the code itself, only the indentations. Writing readable code is quite important, especially when you want help.
I can't speak for the others, but I usually don't even look at untidy code, let alone help correcting it.

Of course everybody has their own preferred way of indenting and stuff, but putting all the brackets in the first row is just bad practice.

On topic:
Using a Popup modal GUI should pause the game, and pausing and unpausing it manually won't be necessary any longer, but you'd still have to move the code above the IsGamePaused()-line.

Ashen

I'll usually try to help, however the code is formatted. It just takes twice as long if I have to untangle it first :) I find indentation especially helpful in locating any mistakes with missing closing braces.
It's really a matter of habit as much anything else, but the way KhrisMUC showed is pretty much the 'standard' IMO.

Quote
But the thing is the game didn't pause when I pressed Escape - I could still see the character.[EGO] idle animations running in the background. When I stuck PauseGame in there, they stopped.
Weird. Popup modal GUIs should act in the same way as PauseGame and do stop Idle anims for me. Still, so long as it works now, I don't suppose it's that important. Just ... weird.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk