How to prevent double action on key pressed

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Idleman

I defined an “interaction key” , and once the key is pressed, a dialog box between player and NPC popup. After the dialog box is on, press the “interaction key” will go to next line of dialog. When dialog goes to the last line, press the “interaction key” will close the dialog popup window.

The problem: When press the “interaction key” to close the dialog window, the dialog window will be activated again at the same time. So the dialog box is keep showing in an endless loop.

Is that a way to make the “interaction key” only works after a release from the previous action. for example, the action of press key to close the dialog window not triggering the opening again. Thank you very much.

:bust_in_silhouette: Reply From: timothybrentwood
func _input(event: InputEvent) -> void:
	if event.is_action_released("interaction key"):
		advance_once_in_dialog()

Thanks for answering my question. Change the action to released works but I still want the actions to happen while press, feels more responsive. In the end, I set a variable as the permission of acting on key press. Press the “interaction key” will close the dialog window, but only after the release action of the key will turn the permission variable to allow, so the dialog will start again by pressing the key again.

Idleman | 2021-05-08 05:56