I want to make a reflex game where you have to press the right arrow key when the button shows up on screen.
There is a penalty if you press the wrong arrow, and I also want to trigger it when the player press any other key on the keyboard.
I tried to use event.ispressed() in a function _unhandledkeyinput(event), BUT the thing is that event.ispressed seems to be true not only when a key is pressed, but also when it is long pressed or when it is released.
here is my function :
func _unhandled_key_input(event):
if etat==etats.ATTENTE and event.is_pressed():
if event.is_action_pressed("ui_up"):
test("haut")
print("UP")
if event.is_action_pressed("ui_down"):
test("bas")
print("DOWN")
if event.is_action_pressed("ui_left"):
test("gauche")
print("LEFT")
if event.is_action_pressed("ui_right"):
test("droite")
print("RIGHT")
else:
faux()
print("not an arrow...")
etat = etats.VERIF
get_tree().set_input_as_handled()
the functions test() is meant to test if an input is right (and I think this part of the code works well). The function faux() is called to show a feedback to the player that it's wrong and change the arrow.
About the outputs I am getting :
- When it says "RIGHT" "LEFT" "UP" or "DOWN", it was always what I typed.
- sometimes, even with a brief press in the good direction, it prints the good direction and "not an arrow"... But not each time !
- when I press multiple arrows, it prints the directions and "not an arrow" sometimes
- when I press an other key, it prints "not an arrow"
I hope I am clear enough !