SOLVED: on_key_press_always()???

Started by alkis21, Thu 26/07/2007 20:12:19

Previous topic - Next topic

alkis21

I find the repeatedly_execute_always() function extremely useful and I resort to it many times while scripting. Has anyone managed to make a similar function (or module) for on_key_press()? I want to be able to use a "magic" button when GUIs are open or when a conversation is playing but I can't figure out whether that's possible or not. For instance, I have an introduction in my game and I want the player to be able to stop watching it by pressing Escape. Or, keys 1-7 set the music volume and I want the player to be able to reduce the volume during a dialog. But I can do neither because you can't assign keyboard functions while a dialog is playing... or can you?

Gilbert

In fact, the on_key_press() function is already called when a GUI (that will pause the game) is on, I think it won't work with blocking situations like during conversation or other blocking calls though.

If you examine the default on_key_press() function, you'll see the first line is:
Code: ags

if (IsGamePaused() == 1) keycode=0;  // game paused, so don't react to keypresses

So if you comment this line, all the following lines in this function will be executed when the game is paused.

If you really want the keys to be checked in other blocking situations, and you actually don't need to check many keys, just do something like below in repeatedly_execute_always():
Code: ags

if (IsKeyPressed(123)) XXXXXXX;
if (IsKeyPressed(124)) XXXXXXX;
blah bla bla


alkis21

#2
Quote from: Gilbot V7000a on Fri 27/07/2007 01:57:07If you examine the default on_key_press() function, you'll see the first line is:
Code: ags

if (IsGamePaused() == 1) keycode=0;  // game paused, so don't react to keypresses

So if you comment this line, all the following lines in this function will be executed when the game is paused.

I'm aware of that, but what if I don't want all keys to work when any GUI is open, but just one key to work when a specific GUI is open?

EDIT: I gave it some thought, perhaps I could edit the line as:

Code: ags
if ((IsGamePaused() == 1) && (GUI[x].Visible=false)) keycode=0;


and then amend my IsKeyPressed lines accordingly.

Quote
just do something like below in repeatedly_execute_always():
if (IsKeyPressed(123)) XXXXXXX;

I never thought of that. I'll try it tonight, thanks.

Gilbert

Quote from: alkis21 on Fri 27/07/2007 09:02:06
I'm aware of that, but what if I don't want all keys to work when any GUI is open, but just one key to work when a specific GUI is open?

EDIT: I gave it some thought, perhaps I could edit the line as:

Code: ags
if ((IsGamePaused() == 1) && (GUI[x].Visible=false)) keycode=0;


Yes, just try to think of the logic depending on the actual needs.
For example if you need only key a, key b, key c to be recognised when GUI x is active (and of course when the game is not paused as well) and void the detection of the other keys when the game is paused you may try something like:

Code: ags

if ((IsGamePaused() == 1) && (GUI[x].Visible=false)) keycode=0;//your line, void all input when GUI x is not active and the game is paused.
if (keycode==a) blah;
if (keycode==b) blah bla;
if (keycode==c) blah bla bla;
if (IsGamePaused() == 1) keycode=0;//void the remaining checks even if GUI x is active
if (keycode == xxx) xxx.....


Since there're many posisbilities, it all depends on how you want it to be implemented, so there's no universal solution.

alkis21

I'm trying to assign Escape in repeatedly_execute_always() so that the introduction is skipped if I press it... but in order for me to quit the introduction, I need to use a NewRoom() function. Unfortunately, I got the error message:

Error: This command cannot be used within repeatedly_execute_always()

Any ideas?

Khris

Make the introduction a cutscene.
Put StartCutScene(eSkipEscOnly); at the beginning, EndCutScene(); at the end (from memory, so check the commands' spelling).

As soon as Esc is pressed, AGS skips right to the line after EntCutscene();

alkis21

I was about to reply that it wouldn't work, as I had tried it before, but I thought I'd give it another shot. I used to put the EndCutScene() function inside dialog_request, as the last thing that occurs in the intro is a dialog line, and the game would hang. This time I put it inside the Player Enter Room (before fadein) section of the first room you end up in after the introduction and it worked!

I'm not sure I understand how StartCutScene function works, if I have a number of SetGlobalInt functions inside the cut scene, will they be executed if the player skips it or not?

Khris

Yes, everything is executed as usual, but in practically zero time.
E.g. a blocking character movement does take place, but the character is placed at the destination coords instead of taking a blocking walk there.

That's why you have to make sure the command line processor gets to the EndCutscene() command, so AGS can switch back to normal, time-consuming execution.

alkis21


Ashen

Do you still need an on_keypress_always function as well, or did Gilbot's suggestions cover that?
I know what you're thinking ... Don't think that.

alkis21

Gilbot's suggestions worked fine.

SMF spam blocked by CleanTalk