How to execute a code until a button is pressed

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

hi!
I have a Texture Button and i want to execute this code as long as the button is pressed

var ev = InputEventAction.new()
ev.action = "move_left"
ev.pressed = true
Input.parse_input_event(ev)
:bust_in_silhouette: Reply From: Shazelz

You could use signals to connect from the texture button to the script, you can connect the button pressed and button release, they make it so when the button is pressed it makes a var true and when it is released it sets it to false and then makes
a while loop (or any other thing) to run when that var is true

var pressed = false
func _on_button_up():
    pressed = false
func _on_button_down():
    pressed = true
func _process(_delta):
   while pressed = true: #or if
     #Thing you want to run

Though this is a solution, I am going to assume that my way is not the most efficient way.

it worked but button_up did not worked
it just continued to execute the code
Still thanks!

Help me please | 2021-06-15 07:45