Pause game while character is talking

Started by JpSoft, Mon 04/05/2009 15:39:01

Previous topic - Next topic

JpSoft

I suppose its a very basical question, but could i pause the game meanwhile one player is talking with the "say" command?

Example: (The code is not correct, but i guess you could udnerstand whatI'm talking about)

I have this is the On_Key_press function (GlobalScript)
Code: ags

if (keycode == EKeyP)
  {
  if (IsGamePaused()) UnPauseGame();
  else PauseGame();
  }


But if i press "P" during a cutscene the game do not pauses. How i could fix this? How i could implement a pause system which will work even in cutscenes? (I really need it since the game have a 10 minutes cut-scene  ::))

Note: The first line that warn AGS to not read keys when the game is paused was erased, so this is not the problem.

Jp

Trent R

I do know that monkey wrote a key_always module (which does something like the rep_exec_always, but for key presses).

Perhaps that's what you're looking for? http://www.adventuregamestudio.co.uk/yabb/index.php?topic=34339.0


Another note, have you tried showing a game-pausing gui? That might work better than a PauseGame() call, and you can even put a label that says "Game is Paused, press P to continue"


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

JpSoft

QuoteAnother note, have you tried showing a game-pausing gui? That might work better than a PauseGame() call, and you can even put a label that says "Game is Paused, press P to continue"

Actually, my actual code shows that GUI too, so it do not works neither. I will check the module. Any other idea?

Jp

GarageGothic

#3
The problem is that Character.Say is a blocking command, so on_key_press isn't being executed. Instead you could check for IsKeyPressed(eKeyP) in your repeatedly_execute_always. You'll probably also have to check for the button being released before allowing it to be activated again, so that holding down P doesn't make the game constantly switch back and forth between paused and unpaused.

Something like this:

Code: ags

bool pressedp;

function repeatedly_execute_always() {
   if ((IsKeyPressed(eKeyP)) && (!pressedp)) {
     if (IsGamePaused()) UnPauseGame();
      else PauseGame();
      pressedp = true;
      }
   else if ((pressedp) && (!IsKeyPressed(eKeyP))) {
      pressedp = false;
      }
   }   


Edit: If you use voice acting in your game, the currently spoken line will play to its end even if the game is paused, and upon resuming the line's text will disappear immediately (as it's timed to the audio).

Trent R

The KeyPressAlways Module (linked in my previous post) expounds upon the code and idea that Garage has posted. Check it out.


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

monkey0506

#5
The KeyPressAlways module is, as Trent says, designed exactly for this type of scenario. If you're only using it for eKeyP then Garage's code might be a lighter alternative, but if you're going to allow several key presses (pause, main menu, save/load menu, quit, etc.) then you might want to check it out.

IIRC there is some discrepancy if you're trying to use normal and always key presses with the module, but it was never widely used so I don't recall what the problem might have been. If you do encounter any issues definitely let me know over at the module thread. ;)

Oh, and just to further advertise (:P) the module also fully supports all Ctrl and Alt key combinations which can be bothersome having to do manually.

JpSoft

I checked your module and its really awesome. I did not include the module itself, but i took many code lines from there (copy+paste); practically, you did the work for me ;D Thanks a lot.

Yes, i needed many different keys available all the time, and your module works perfect for it. Honestly, this is one of the best AGS modules i never saw. Since i did not need differet job for "pressing" or "taping", i could not precise where it have troubles.

Again, thanks a lot.

Jp

PS Actually, maybe a built-in On_Key_Press_Always will be very nice too  :=

monkey0506

You're definitely welcome. I'm glad you were able to take something from the code.

Really the module is just doing the same thing as what GG did above, it just expounds upon the idea. If you have two variables, one to store the current key press and one for the last key press, then all you have to do is check if the last key is still being held down, otherwise update the current key and react to that. ;) In case anyone was wondering.

SMF spam blocked by CleanTalk