Pause Game except GUI - SOLVED

Started by Kinoko, Wed 07/07/2004 03:40:14

Previous topic - Next topic

Kinoko

I'd like to be able to have a GUI you can turn on at almost any point in the game, and when this GUI is on, everything going on in the background pauses. If I use PauseGame() with the opening and closing of the GUI, it works fine except I can't use keypresses to navigate around and use the GUI. Is there any way around this?

Gilbert

Hmmm change it to a popup modal? (this way you don't need to call the pause and unpause game yourself)

The reason the game won't respond to key press while paused is due to this line:
  if (IsGamePaused() == 1) keycode=0;  // game paused, so don't react to keypresses

in the default global script code of the function on_key_press(), if you remove it, the game will respond to key presses during game pause. If you ONLY want the keys to be recognized while that GUUI's on and the game's pause, you can change that line to stuff like:

  if ((IsGamePaused() == 1)&&(IsGuiOn(BLAH)==0)) keycode=0;  // game paused and GUI BLAH is not on, so don't react to keypresses

Kinoko

#2
Hmm, well my whole game is based on key presses (mouse isn't used at all).

I need keypresses to be available normally and while the GUI is up (even if it's only the certain keys needed to navigate the GUI at that time).

Basically, I want the game in the background to effectively freeze when the GUI is up. Not just stop responding to things, I'd like it to freeze on whatever it's currently doing (even if it's in the middle of an animation or something). As far as I understand it, this is currently what PauseGame() does normally. I just need control over the GUI while this is happening.

I'm writing this thinking about how impossible I'm sure it is... but I wanted to ask just in case there was something I couldn't think of (which is also very likely).

EDIT: In normal gameplay, the arrow keys held down move the character. They also move from option to option in the GUI. As it was, if I opened the GUI, the arrow keys would move them both (you'd see the character walking around underneath the GUI as you choose various options - which is not what I want). Also, I couldn't use other keypresses (X, Z, etc) to choose options in the GUI. It seems only the arrow keys worked.

I changed the GUI to popup modal, and commented out the if (IsGamePaused() == 1) keycode=0;  line.

Now, the character doesn't move when I navigate around the GUI, and the X and Z keys etc. work fine, but the game still isn't -paused- as such beneath the GUI. The character doesn't walk, but he does face different directions when I use the arrow keys.

I'll post the section of global script this relates to:

Code: ags

#sectionstart on_key_press  // DO NOT EDIT OR REMOVE THIS LINE
function on_key_press(int keycode) // called when a key is pressed. keycode holds the key's ASCII code
  {
//  if (IsGamePaused()==1) keycode=0; // game paused, so don't react to keypresses
  if (keycode==17) QuitGame(1); // Ctrl-Q
//  if (keycode==363) SaveGameDialog(); // F5
//  if (keycode==365) RestoreGameDialog(); // F7
  if (keycode==367) RestartGame(); // F9
  if (keycode==434) SaveScreenShot("scrnshot.pcx");  // F12
//  if (keycode==9) show_inventory_window(); // Tab, show inventory
  if (keycode==19) Debug(0,0); // Ctrl-S, give all inventory
  if (keycode==22) Debug(1,0); // Ctrl-V, version
  if (keycode==1) Debug(2,0); // Ctrl-A, show walkable areas
  if (keycode==24) Debug(3,0); // Ctrl-X, teleport to room
  
//////////////////////////////GUI STUFF////////////////////////////////////

if ((IsGUIOn(2)==0) && (keycode==83)) {
//PauseGame();
  GUIOn(2);
  ListBoxSetSelected(2,0,0);
}
else if ((IsGUIOn(2)==1) && (keycode==83) && (IsGUIOn(3)==0) && (IsGUIOn(4)==0) && (IsGUIOn(5)==0) && (IsGUIOn(6)==0)) {
  GUIOff(2);
//UnPauseGame();
}

///////declaring buffer
string buffer;
ListBoxGetItemText (2,0,ListBoxGetSelected(2,0),buffer);
///////

if ((IsGUIOn(2)==1) && (IsGUIOn(3)==0) && (IsGUIOn(4)==0) && (IsGUIOn(5)==0) && (IsGUIOn(6)==0) && ((IsKeyPressed(380)==1) || (IsKeyPressed(50)==1)))  {
  if (StrComp("ITEMS",buffer)==0) {
    ListBoxSetSelected (2, 0, 1);
    }
  else if (StrComp("MAGIC",buffer)==0) {
    ListBoxSetSelected (2, 0, 2);
    }
  else if (StrComp("STATS",buffer)==0) {
    ListBoxSetSelected (2, 0, 3);
    }
  else if (StrComp("EQUIP",buffer)==0) {
    ListBoxSetSelected (2, 0, 0);
    }
}

else if ((IsGUIOn(2)==1) && (IsGUIOn(3)==0) && (IsGUIOn(4)==0) && (IsGUIOn(5)==0) && (IsGUIOn(6)==0) && ((IsKeyPressed(372)==1) || (IsKeyPressed(56)==1)))  {
  if (StrComp("ITEMS",buffer)==0) {
    ListBoxSetSelected (2, 0, 3);
    }
  else if (StrComp("MAGIC",buffer)==0) {
    ListBoxSetSelected (2, 0, 0);
    }
  else if (StrComp("STATS",buffer)==0) {
    ListBoxSetSelected (2, 0, 1);
    }
  else if (StrComp("EQUIP",buffer)==0) {
    ListBoxSetSelected (2, 0, 2);
    }
}

if ((IsGUIOn(2)==1) && (StrComp("ITEMS",buffer)==0) && (keycode==88)) {
  GUIOn(3);
}

else if ((IsGUIOn(2)==1) && (StrComp("MAGIC",buffer)==0) && (keycode==88)) {
  GUIOn(4);
}

else if ((IsGUIOn(2)==1) && (StrComp("STATS",buffer)==0) && (keycode==88)) {
  GUIOn(5);
}

else if ((IsGUIOn(2)==1) && (StrComp("EQUIP",buffer)==0) && (keycode==88)) {
  GUIOn(6);
}

if ((IsGUIOn(3)==1) && (keycode==90)) {
  GUIOff(3);

}
if ((IsGUIOn(4)==1) && (keycode==90)) {
  GUIOff(4);

}
if ((IsGUIOn(5)==1) && (keycode==90)) {
  GUIOff(5);

}
if ((IsGUIOn(6)==1) && (keycode==90)) {
  GUIOff(6);

}

Gilbert

Where're the character's arrow key moving codes? I suppose they're some codes in repeatedly execute using IsKeyPressed() or something right?

In that case just put the part of code you don't want to be executed (eg. the arrow moving code) while the game is paused into an if condition. Example:

From:

// this is part of code for moving the character via keyboard.
blah bla bla bla...


to:

if (IsGamePaused()==0) {
Ã,  // this is part of code for moving the character via keyboard.
Ã,  blah bla bla bla...
}


Kinoko

That will solve the problem of the character moving when the GUI is up, (thanks!) what what about all the other hundreds of things that could be happening at any time in the game? I understand that this is stopping the character I control, but there will be character/enemies moving about by themselves and at various times attacking me. Will these things be stopped as well with the popup modal etc? Also, what if say, an enemy character is in the middle of a particular animation leading to an attack. Will this freeze the movement, or just stop him from continuing after it's done?

(Sorry to sound pushy :) I don't have any of these characters or systems made up yet so I can't test them myself and I'm just not entirely sure how this works yet).

Pumaman

When the game is paused, it basically stops any game loops from running. A game loop is the part of AGS that moves and animates things on the screen.

Any command such as FaceLocation that has an instant affect will still work while the game is paused, which is why you're seeing that happen with the arrow keys.

Bad guys won't move or attack since their movement will be stopped by the game being paused.

Kinoko

Thanks, I understand now. Works great ^_^

SMF spam blocked by CleanTalk