Speech While Game Paused by GUI

Started by Baron, Thu 25/09/2014 03:09:02

Previous topic - Next topic

Baron

Hey,
    This one seems pretty simple on the face of it, so I'm asking in the beginners' forum.  I want to have my character speak when the inventory GUI is open, for example to describe an inventory item.  But when the GUI is up the game is necessarily paused (I know I can set it to not be paused, but I do want it paused for all other purposes), so although the text comes up (and the speech sound file plays), it doesn't disappear unless there is a mouse click.  I want the same speech behaviour as when the game is unpaused (ie speech disappears after a period based on its length or when an associated speech audio file is done playing).

1) Does anyone have any ideas?

2) Does anyone know if there is a game timer independent of whether the game is paused?  The conventional ones all freeze.

I'm using 3.3.0 and no modules. 

monkey0506

My first thought is that you could probably get away with a simple extender to unpause the game, say the text, then pause the game again...

Code: ags
void SayWhilePaused(this Character*, String text)
{
  bool paused = IsGamePaused();
  if (paused) UnPauseGame();
  this.Say(text);
  if (paused) PauseGame();
}


As for a timer that runs independently of whether the game is paused, this is why I discourage anyone from using the built-in SetTimer function -- ever. All you need is a global variable. Granted, you do have to update it yourself, but to set it, you just set the value of the variable. Then in repeatedly_execute you can do:

Code: ags
  if (timer) timer--;


This also allows you to check IsGamePaused or update it in repeatedly_execute_always for timers that run during blocking events. There's a number of ways to approach the problem, but the extender is probably the simplest.

SMF spam blocked by CleanTalk