How to create a loop with Input

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

Hello all, how can I create a loop (while or for) this way:

while (input != Input.is_action_just_pressed("confirm")):
>   do something until the key is pressed

I tried some ways, but no one works, like that:

func start_blink(event):
while event != InputEventKey:
	$titulo/aperte.modulate = Color(1,1,1,1)
	yield(get_tree().create_timer(.3), "timeout")
	$titulo/aperte.modulate = Color(1,1,1,0)
	yield(get_tree().create_timer(.3), "timeout")

P.S.: I’m new on godot

:bust_in_silhouette: Reply From: whiteshampoo

You cannot “wait” for an Input.
the builtin functions like _ready or _process need to run without endless loops.

Depending on your need, you can try this:

func _process(delta : float) -> void:
    if not Input.is_action_pressed("confirm"):
        # do something if the key is pressed
        # do something else if key is not pressed

or declare a variable already_pressed and do it like this:

var already_pressed : bool = false

func _process(delta : float) -> void:
    if Input.is_action_just_pressed("confirm"):
        already_pressed = true
    if already_pressed:
        # do something if the key was pressed
        # do something else, if key was not pressed yet

(Code not tested, maybe i mistyped somewhere!)

removed some typos