Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mariano Cirigliano on Fri 29/10/2010 23:00:52

Title: I have a "GUI" and need that it recognizes "keyboard"
Post by: Mariano Cirigliano on Fri 29/10/2010 23:00:52
I have a "GUI" and need that it recognizes "keyboard"

On having touched the letter "S" I need that it is opened " QUITGAME (0);

On having touched the letter "N" I need that one comes back to the game.

I hope that my question is understood.

Thanks to all!. ???
Title: Re: I have a "GUI" and need that it recognizes "keyboard"
Post by: mode7 on Fri 29/10/2010 23:55:54
I would do it like that

function repeatedly_execute() {
if (gYOURGUI.Visible == true)
    {
     if (IsKeyPressed (eKeyS) == true) QuitGame(0);
     if (IsKeyPressed (eKeyN) == true) gYOURGUI.Visible == false;
    }
}
Title: Re: I have a "GUI" and need that it recognizes "keyboard"
Post by: monkey0506 on Sat 30/10/2010 00:35:13
You don't have to use repeatedly_execute. In fact it's probably less efficient than just using on_key_press since you're duplicating a check done internally. Do something like this:

function on_key_press(eKeyCode keycode) {
  if (IsGamePaused()) { // game is paused, ignore most keys
    if (gYourgui.Visible) {
      if (keycode == 'S') QuitGame(0);
      else if (keycode == 'N') gYourgui.Visible = false;
    }
    // else..other GUIs that need to pause the game but intercept keypresses
  }
  // ...the rest of your normal keypresses here
}