GUI based in Loom

Started by nightmarer, Sun 19/04/2020 22:02:25

Previous topic - Next topic

nightmarer

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.

ManicMatt

#1
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.

Khris

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
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
  }

}

Slasher

Beaten  (laugh)

Oh, well... as per Khris...

ManicMatt

If someone pressed all the keys at the same time like a mad man, would it cope with that?

Snarky

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.

ManicMatt

Ah ok, just wondered for future reference.

You always have to anticipate a player to incorrectly play your game!

nightmarer

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.

SMF spam blocked by CleanTalk