Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Cino on Mon 24/12/2007 02:14:09

Title: PauseGame issue
Post by: Cino on Mon 24/12/2007 02:14:09
It was over a year ago when I tried finding a solution to my problem without a result, so I gave up. I started working on it again now and still no improvement.
What I wanted to achieve, is a pause button that pauses the game anytime, even during cutscenes, just like lucasarts games.
So I put a PauseGame(); function in repeatedly_execute_always() and also pop up a GUI when a space key is pressed. It works fine in normal game, but still does not stop some things from moving on.
Let's say I've got an "enters room after fade-in" room script containing two lines:
Wait(xxx);
player.ChangeRoom(xxx,xxx,xxx);

When I press space during that, the pause GUI pops up, but the room still changes after xxx cycles, basically ignoring the pause.
Anyway, is it even possible to pause that kind of thing in AGS? Or will I have to accept that you can only pause when you're playing?
Title: Re: PauseGame issue
Post by: Khris on Mon 24/12/2007 13:10:41
You could use a function like this:
function noloopcheck pause_game(GUI*pausegui, int keycode) {
  pausegui.Visible=true;
  bool cont;
  while (!cont) {
    if (IsKeyPressed(keycode)) cont=true;
    Wait(1);
  }
  pausegui.Visible=false;
}


That should pretty much put AGS to a screeching halt in its tracks.
Title: Re: PauseGame issue
Post by: Cino on Mon 24/12/2007 14:27:11
Well, basically it worked, though I had to ditch the Wait(1); line, since AGS does not allow blocking functions in repeatedly_execute_always and the GUI didn't pop up neither, so I modified the code a bit and here is the working one in case anyone else needs it:


function noloopcheck pause_game() {
  bool cont;
  while (!cont) {
    if (!IsKeyPressed(32)) cont=true;
  } // wait for the user to release the key
  while (cont) {
    if (IsKeyPressed(32)) cont=false;
  } // wait for the user to press the key
  while (!cont) {
    if (!IsKeyPressed(32)) cont=true;
  } // wait for the user to release the key
  gPaused.Visible=false;
}

function repeatedly_execute_always() {
  if (gPaused.Visible)
    pause_game();
  if (IsKeyPressed(32))
    gPaused.Visible=true;
}


As you see, the game is actually paused in the next cycle after the gPaused GUI is made visible.

Thanks KhrisMUC.
Title: Re: PauseGame issue
Post by: monkey0506 on Mon 24/12/2007 22:21:08
Khris's function was not designed for this:

function pause_game(GUI* pausegui, int keycode) {
  // blah
  }

function repeatedly_execute_always() {
  if (gPaused.Visible) pause_game();
  }


It was designed to be used like this:

function pause_game(GUI* pausegui, int keycode) {
  // blah
  }

function on_key_press(int keycode) {
  if (keycode == 32) pause_game(gPaused, 32); // pause game on space bar pressed until space bar pressed again
  }


But as long as you got it working the way you want, it's all good, right? ;)
Title: Re: PauseGame issue
Post by: Cino on Wed 26/12/2007 13:05:33
But on_key_press is not called when there are blocking scripts running, so that would not have worked.
Title: Re: PauseGame issue
Post by: monkey0506 on Thu 27/12/2007 04:01:45
Oh, duh. Well you could have done:

function repeatedly_execute_always() {
  if ((!gPaused.Visible) && (IsKeyPressed(32))) pause_game(gPaused, 32);
}


But again, as long as you got it working. :=