0 votes

Im making a typing game to familiarize myself with this side of godot, and im having some issues with unhandledkey_input(event). I know its SUPPOSED to return 2 values, but I need it to return a value only when im pressing the key, and not when its being released. This is because after the first time its pressed, my code tells it to move to the next letter in the word, which is then though of as incorrect.

Example: The word is "Hello!" so when I press H, it is correct when pressed, but incorrect when released because its checking for the value "e" but gets "h".

Heres the code im using for this currently, if you need to see it. Just fyi, the whole "WordProgress" thing is just to show how far along you are into the word, it has no significance for this issue.

func _unhandled_key_input(event):
    var KeyPressed = event.as_text()
    check_event(KeyPressed)




func check_event(event):
    if event == KeyArray[Currentletter]:
        if event != "Space":
            $WordProgress.text += str(event)
        else:
            $WordProgress.text += "_"
        Currentletter += 1
        if Currentletter == LengthOfWord:
            word_completed()
    else:
        punish()
in Engine by (12 points)

1 Answer

0 votes

Maybe try adding a check if the key is pressed or released
if event.pressed:

by (408 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.