ESC key to turn gui on/off

Started by KingMick, Wed 19/04/2006 11:31:15

Previous topic - Next topic

KingMick

Ok, so I'm trying to make the gui turn on and off with the press of the ESC key.  I wrote code that I thought would work, but it only works halfway--the ESC key turns the gui on but not off.  Here's the code:

  if (keycode == 27) {
    if (gMaingui.Visible == true) {
      gMaingui.Visible = false;
    }
    else {
      gMaingui.Visible = true;
    }

This is in the on-key-press function.  The gui itself is a Popup Modal, does that disable keypresses or something?

I'm probably doing something very dumb or overlooking something very obvious.  Any help would be appreciated.

Gilbert

It depends on how the on_key_press() function looks like.

By default, the on_key_press() function is like:

function on_key_pressed(int keycode) {
  if (IsGamePaused() == 1) keycode=0;
  ...blah bla bla

The line with bolded text is the one that is causing the problem, its originally purpose was to prevent the game from parsing any key press when the game is paused (which is true when a popup modal GUI is on).

There're many ways around this, one way is, of course, comment out the line mentioned about, but this may not be teh best solution, as it'd beat the original purpose of it. I'll suggest you move the part detecting ESC to above that line and it should work.

KingMick

Ah!  I guess I didn't take into account the fact that the GUI would pause the game!  I knew it was something obvious.  Thanks Gilbot--I didn't realize changing the order would actually solve the problem, so that's what I'll do.  I appreciate your help.

SMF spam blocked by CleanTalk