Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Gilbert on Tue 13/04/2004 02:22:39

Title: Feature request: FlushKeyPressed()
Post by: Gilbert on Tue 13/04/2004 02:22:39
Hmmm I don't know if there're easy ways to do this currently but seems that similar function was not provided with V2.6SP1 (with which I had to do some messy scriptings to get past this).

The problem is this:
When a game is "not in control" (eg. while running blocking functions) the function on_key_pressed() (either global or room ones) won't be executed, this is okay and is the expected behaviour.

However if the player pressed a key just before the (series of) blocking sequence (eg. a cutscene), it's possible that the key pressed got recognized, but the on_key_pressed() function would be execute afterwards, which may not be desired sometimes. (Eg. In a game, the player accidentally pressed TAB before a cutscene started, it's possible that the inventory GUI would pop up after the cutscene, which is not always expected).

So, I suggest adding a new function: FlushKeyPressed(), which the game designers can put it in wherever suitable places (eg. at the end of a long animation), which will clear the currently pressed key, to prevent the on_key_pressed() function triggered for some reasons.


EDIT: Oops! How f00lish I am! I clicked the wrong forum and didn't notice. Please move this to the tech forum.
Title: Re:Feature request: FlushKeyPressed()
Post by: strazer on Tue 13/04/2004 03:53:24
Have you tried something like this?:
Global script
----------------

int ignorekeypress=0;

function FlushKeyPressed() {
 ignorekeypress=1;
}

function on_key_press(int keycode) {
 if (ignorekeypress==1) {
   ignorekeypress=0;
 }
 else {
   // process keys
 }
}

// if keys are processed in rooms as well, add:

 export ignorekeypress;

 Script header
 -----------------
 import int ignorekeypress;


Edit: Hm, I've just realised that any key pressed after the FlushKeyPressed call would be ignored too...Ok, forget it then.
Title: Re:Feature request: FlushKeyPressed()
Post by: Gilbert on Tue 13/04/2004 04:09:08
Quote from: strazer on Tue 13/04/2004 03:53:24
Edit: Hm, I've just realised that any key pressed after the FlushKeyPressed call would be ignored too...Ok, forget it then.

Right, that's my point, the problem was that it recognizes the key pressed BEFORE the sequence.
As I mentioned before, I had fixed my problem with some messy codes, but a function like this can still be handy.
Title: Re:Feature request: FlushKeyPressed()
Post by: Pumaman on Tue 13/04/2004 18:18:38
I think the best solution here is simply for it not to queue up an on_key_press if the game is blocked. I'll add it to my list.
Title: Re:Feature request: FlushKeyPressed()
Post by: Gilbert on Wed 14/04/2004 02:53:22
Yeah that's a good solution too.