Topic was automatically imported from the old Question2Answer platform.
Asked By
genete
Old Version
Published before Godot 3 was released.
I have the following code for a node:
extends Node2D
func _ready():
set_process(true)
pass
func _process(delta):
var add_credit=Input.is_action_pressed("add_credit")
if add_credit:
get_node("/root/global").credits+=1
update_credit_value()
func update_credit_value():
get_node("Value").set_text(str(get_node("/root/global").credits).pad_zeros(2))
If I press the key that correspond to “add_credit” action, the credit increases to 5 or 6 instantly. How do I avoid that and read one key input at a time?
You’re checking if “add_credit” is pressed every frame, so if you tap the button you will probably tap it for multiple frames, and if you hold the button down you will increase it every frame. So instead of using _process() you’ll want to use _input() so you can trigger the adding only once when the button is pressed.