Escape Key - Close GUI

Started by Darth Mandarb, Tue 20/01/2004 22:56:07

Previous topic - Next topic

Darth Mandarb

I want to be able to press the Escape key to close my inventory GUI.

So I put this code into the script for my Inventory GUI:

if (IsKeyPressed(27)==1) {
GUIOff(4); // Shuts off Inv. GUI
GUIOn(1); // Turns back on my main GUI
SetDefaultCursorMode();
}


This returned no results.  Pressing the escape key did nothing.  So next I added this line to my Global Script:

if (keycode==27)  GUIOff(4) & GUIOn(1) & SetDefaultCursor(); // Shuts off Inventory GUI

And still nothing.

Next, I took this code from the global script and added it into the GUI script:
function on_key_press(int keycode) {
 // called when a key is pressed. keycode holds the key's ASCII code
 if (keycode==17)  GUIOn(0) & SetCursorMode(6);   // Ctrl-Q


This gave me errors about nested functions, no closing brace, etc.  I'm not really up on functions and variable and all that :(

Finally the question:
Anybody know how to make the escape key shut off a GUI?

This from the Help File:
"The "Popup modal" option means that the GUI will be initially off and must be turned on by a text script command. With this option, the game will be paused while the GUI is displayed, during which time the on_mouse_click and on_key_press functions will not get run.

So, if I change it to normal and just shut if off when the game starts will it then be able to accept keypress commands?

Thanks guys!

])]V[

Scorpiorus

Yes, make it Normal. Then on game_start GuiOff(gui);

function on_key_press(int keycode) {

if (keycode == 27) GuiOff(gui);
...

}

~Cheers

Darth Mandarb

Once again you've saved the day.

If you don't win the FOREGO I will go on strike!!

Thanks man!

darth

Scorpiorus

#3
Hehe, thanks. Personally, I think there are many people around who really deserve the tech award (I'm not just talking about the answered AGS/script questions).

~Cheers

SMF spam blocked by CleanTalk