Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: nightmarer on Sun 19/04/2020 22:02:25

Title: GUI based in Loom
Post by: nightmarer on Sun 19/04/2020 22:02:25
Good evening all.

I am working in a GUI that my character opens when he clicks with one cursor(cast) and he has to play musical notes using the keyboard.
I'm thinking how to do it fine. First of all I would like to play a sound when they push any key (from A to G), should I do this with the Text Parser?
I think that maybe Text Parser is not for this as it is needed to do a group of words released separately (remember Loom CACD, each key emit one sound and changed the Gui background, if it was the right combination then something mayl happen).
Do you have any sample of something similar or any idea to get this efficiently?

Regards.
Title: Re: GUI based in Loom
Post by: ManicMatt on Mon 20/04/2020 07:29:45
Gosh, that would be possible, like maybe having a condition of a key press whilst the gui is visible, then setting a value, but there's so many ways that a player could mess it up, like pressing multiple keys at the same time, that personally, id just have the mouse click on the keys in a gui onscreen, as far less can go wrong haha. I can't imagine a text parser would be effective but I've no experience with those.

Additionally, don't some people have keyboards with different layouts?

well, someone might know how to accomplish what you ask, in detail, i just thought I'd throw in my two cents.
Title: Re: GUI based in Loom
Post by: Khris on Mon 20/04/2020 08:25:45
You can handle keypresses using on_key_press(), you just need a way to check multiple subsequent ones. One easy way is to put them in a string.

Code (ags) Select
String notes = "";

function CheckAction() {
  if (notes.CompareTo("CACD") == 0) {
    ...
  }
}

function on_key_press(eKeyCode k) {

  // existing code here

  // new code: is gNotes visible and key valid note?
  if (gNotes.Visible && k >= eKeyA && k <= eKeyG) {
    notes = notes.AppendChar(k);
    // play sound, etc.
    // if it was fourth note, compare to valid sequences
    if (notes.Length == 4) CheckAction();
    notes = "";  // clear played notes
  }

}
Title: Re: GUI based in Loom
Post by: Slasher on Mon 20/04/2020 08:30:32
Beaten  (laugh)

Oh, well... as per Khris...
Title: Re: GUI based in Loom
Post by: ManicMatt on Mon 20/04/2020 13:33:03
If someone pressed all the keys at the same time like a mad man, would it cope with that?
Title: Re: GUI based in Loom
Post by: Snarky on Mon 20/04/2020 13:40:15
Yes.

Of course, the order in which it detects the keys would be more or less random, and many keyboards cannot actually detect more than about 4 keys simultaneously depressed (also, the AGS event buffer size is limited), so it might ignore some keys. But it wouldn't crash or anything.
Title: Re: GUI based in Loom
Post by: ManicMatt on Mon 20/04/2020 15:32:18
Ah ok, just wondered for future reference.

You always have to anticipate a player to incorrectly play your game!
Title: Re: GUI based in Loom
Post by: nightmarer on Mon 20/04/2020 17:38:19
Hello.

I'll give it a try. The GUI is only displayed when the character makes an action with a hotspot, character, object and so on.
So it wouldn't be any problem with it, the same that happened with loom.
I will tell you it it works.
Thank you very much.

Regards.