Having WaitMouseKey Ignore Certain Keys

Started by hocuspocus2, Sun 19/06/2022 21:49:09

Previous topic - Next topic

hocuspocus2

I have a custom Say function that's like this:
Code: ags

void Saying(this Character*, String msg) {  
  gSpchWindow.Visible = true;
  lSpeechText.Text = msg;
  lSpeakerName.Text = this.Name;
  
  while (WaitMouseKey(40) == 0 && !Game.SkippingCutscene) { // wait until key or mouse click
  
    /*...Irrelevant animation code...*/
    
  }
  
  gSpchWindow.Visible = false;
}


This function works fine. The problem is with WaitMouseKey, in that during a cutscene with lots of dialogue, I'd like the player to be able to pause the game during the cutscene (by pressing P, for example). Pressing P during a cutscene while the speech GUI is visible doesn't do anything, it just treats it like any key press. So I was wondering how I could have the WaitMouseKey in this code ignore certain keys?

In truth, I was originally trying to have the function only respond to mouse clicks and the Enter key, instead of responding to any mouse clicks/key presses. I tried to do it by modifying the loop to something like:
Code: ags

while (!Mouse.IsButtonDown(eMouseLeft) && !IsKeyPressed(eKeyReturn) && !Game.SkippingCutscene) {
  while (WaitMouseKey(40) == 0) {
   /*....*/
  }
}

Which I suppose worked with the speech aspect, but would also cause some bugs in other areas, and not "queue" speech lines.

eri0o

Uhm, did you try instead of using an event to respond to the P keypress, use rep exec always and doing a key press like check there? Or alternatively, skip the 40 in WaitMouseKey and let it be infinite? Just trying to think on alternatives.

Crimson Wizard

#2
Please tell, which version of AGS are you using? In 3.6.0 all the Wait* functions now have the pressed key code in the return value:
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Wait.html
so if you use that, you could test which key was used, and if it's a "wrong" one then continue looping and waiting.

Code: ags

while (!Game.SkippingCutscene) {
    int skip = WaitMouseKey(40);
    if (!((skip & eInputKeyboard) && ((skip & 0xFFFF) == eKeyP))) // scary bitwise math
        break; // break out if anything BUT eKeyP code
    /*...Irrelevant animation code...*/
}


I cannot predict if that will work exactly as you like though.
Other than that, like eri0o said, perhaps all this could be redesigned by checking for IsKeyPressed in rep exec always, but I cannot clearly imagine details right now, this is something to ponder upon.

hocuspocus2

Sorry for the late reply, I use version 3.5.0. I tried adding an IsKeyPressed() to the rep exec always, but it seems to be a bit buggy. Even when it does pause the game, clicking the mouse still triggers the Saying function when it's in a cutscene (ie when there's multiple lines "queued" or when the player goes to a different room right after the dialogue).
I like the pressed key code return value idea, but I'm currently a bit wary of using 3.6.0 on my game when it's in beta, so I think I will put this issue in the backburner of my game's todo list until the 3.6.0 official release.

SMF spam blocked by CleanTalk