PauseGame issue

Started by Cino, Mon 24/12/2007 02:14:09

Previous topic - Next topic

Cino

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?

Khris

You could use a function like this:
Code: ags
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.

Cino

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:

Code: ags

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.

monkey0506

Khris's function was not designed for this:

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

Code: ags
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? ;)

Cino

But on_key_press is not called when there are blocking scripts running, so that would not have worked.

monkey0506

Oh, duh. Well you could have done:

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


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

SMF spam blocked by CleanTalk