keypress global function blocked during Quit_GUi? [SOLVED]

Started by TheMagician, Wed 09/02/2005 07:19:52

Previous topic - Next topic

TheMagician

Hi everybody.
I made a custom Quit dialog for my game and now I want to script some keyboard interaction for it (for example: hit enter to quit the game.)

I tried using the on_keypress global function but it seems to be blocked while the GUI is active. Is that true or did I do something wrong?
I did

function on_keypress (int keydown) {
if (keydown==555) {
if (IsGUIOn(QUIT)==1) {
Code for the action

Well, it just didn't work.
Right now I have my code in the repeatedly execute like this:

if (IsKeyPressed(555)==1) && (IsGuiOn(QUIT)==1) ...

It works ok, but
Is this the correct way of doing it?

btw: AGS 2.62

Thanks in advance,
Stefan

Radiant

I'm not sure what key '555' refers to, but the enter key is actually key 13. That might help.
But putting it in rep_ex is certainly a suitable alternative.

Ashen

Key presses aren't handled when the game is paused, e.g. by a popup modal GUI, because of the first line of on_key_press:
Code: ags

function on_key_press(int keycode) {
Ã,  if (IsGamePaused() == 1) keycode=0;Ã,  // game paused, so don't react to keypresses
Ã,  //codes for other keys
}


So, assuming your Quit GUI is popup modal and that's the problem, something like:
Code: ags

function on_key_press(int keycode) {
Ã,  if (keycode==13) && (IsGUIOn(QUIT)==1) {
Ã,  Ã,  Code for the action
Ã,  }
Ã,  else if (IsGamePaused() == 1) keycode=0;Ã,  // game paused, so don't react to keypresses
Ã,  //codes for other keys
}

Anything else you wanted to happen when the game was otherwise paused should also go above else if (IsGamePaused() == 1) ....

Also, have you actually created the on_keypress function in your script, or is that just how you've typed it here? (EDIT: I thought it might be, but it doesn't hurt to check these things.) The function on_key_press already exists, so your function wouldn't do anything.
I know what you're thinking ... Don't think that.

TheMagician

Thanks for your answers!

@Radiant:
I just typed 333 because I didn't know the correct ASCII code for "Enter".
However, in my script I wrote 13.

@Ashen:
QuoteAlso, have you actually created the on_keypress function in your script, or is that just how you've typed it here?

That's just what I typed here. Of course in the game I took the correct function.
However, many thanks for explaining the behaviour of the function! This made everything clear! ... once again (thanks to this great forum!)Ã,  :)

SMF spam blocked by CleanTalk