Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: arj0n on Sun 04/04/2010 19:56:20

Title: Check if Esc is pressed while fading in or out of a room
Post by: arj0n on Sun 04/04/2010 19:56:20
How can I build a check (I guess it needs to be in repeat exec.) that checks whether the
escape button is pressed or not even when fade-in or fade-out of a room is happening?

This part works but not when fading in or out of a room, only when a room is normally show:
------------------------------------------------------------------------------------------
function on_key_press(eKeyCode keycode) {
 // FUNCTION KEYS AND SYSTEM SHORTCUTS
 if (keycode == eKeyEscape) {
   // ESC
   mouse.Visible = true;
   QuitGame(1);
   mouse.Visible = false;
------------------------------------------------------------------------------------------
Thanx.
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: Crimson Wizard on Sun 04/04/2010 20:14:20
I guess you should rather check inside "before fade in" function using IsKeyPressed.
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: arj0n on Sun 04/04/2010 22:45:44
In this situation, lot's of random rooms are shown.
During this being shown, I'd like to be able to check if the Esc button has been hit, also during the fading between the rooms.

"On_key_press" is used but only works when before and after the fading.
Is there another way then adding the "enter room before fade in" options of all these rooms
in order to get this esc-button check working during fading?
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: Crimson Wizard on Sun 04/04/2010 22:58:30
Hmm... what about putting the IsKeyPressed check into global repeatedly_execute function?
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: discordance on Sun 04/04/2010 23:09:19
You can use the "on_event" function to capture fade ins and fade outs for every room.
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: arj0n on Sun 04/04/2010 23:36:14
This still doesn't work when the fadeout starts...:
Can't find an event for when the fadeout has started already.


function on_event(EventType event, int data) {
 if (event == eEventEnterRoomBeforeFadein) {
   if ((data >= 1) && (data <= 10)) { // only set the timer for the rooms that are going to use it
     SetTimer(1, GetGameSpeed() * sldSpeed.Value);
   }
   else SetTimer(1, 0); // disable the timer for other rooms
 }

if (event == eEventEnterRoomBeforeFadein) {
if (IsKeyPressed(eKeyEscape)){
   mouse.Visible = true;
   QuitGame(1) ;
   mouse.Visible = false;
if (event == eEventLeaveRoom){
if (IsKeyPressed(eKeyEscape)){
   mouse.Visible = true;
   QuitGame(1) ;
   mouse.Visible = false;
}
}
}
}
}
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: Khris on Sun 04/04/2010 23:47:57
on_event and room_Load are only run once; the check must be inside a function that runs repeatedly.
Not sure if it's possible to catch keypresses during fading.
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: tzachs on Sun 04/04/2010 23:52:09
Have you tried checking in repeatedly_execute_always? I think it's your best shot...
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: arj0n on Sun 04/04/2010 23:59:03
If tried the function repeatedly_execute() but that only works when there's no fading...
So like Khris said, I'm not sure if there a way to catch keypressing during fading.
eEventEnterRoomBeforeFadein sometimes seems to work.

So I can't find a way to catch the keypress when having a fade-out plus
the eEventEnterRoomBeforeFadein doesn't always react  ???
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: Khris on Mon 05/04/2010 00:01:34
Like I said, it is called once.
Before the new room fades in, AGS calls on_event(eEventEnterRoomBeforeFadein, room), then the room's room_Load.
If you happen to hold Esc down right when the function is run, it is catched.

Try putting it in rep_ex_always.
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: Calin Leafshade on Mon 05/04/2010 00:07:17
rep ex always is not called during fades
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: Crimson Wizard on Mon 05/04/2010 00:10:20
What about setting room transition to "instant" and making manual fade-in/out? This sounds complicated, but could still be useful if you seek perfection.
Don't have any more ideas atm.
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: Khris on Mon 05/04/2010 06:56:43
Yeah, that's the only feasible way it seems.
Use a screen-sized black GUI and fade its transparency. Either check for IsKeyPressed(eKeyEsc) during the fade loops or fade it non-blocking, then you can use on_key_press.
Title: Re: Check if Esc is pressed while fading in or out of a room
Post by: arj0n on Mon 05/04/2010 09:03:49
Darn. But thanx.  :)