Wait for user Input

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By vonflyhighace2
:warning: Old Version Published before Godot 3 was released.

Is there a way to basically yield a function in order to wait for user input, then resume after from where it left off? I’ve tried using the yield statement but I just can’t get it to work. can Anyone share an example of how its done?

:bust_in_silhouette: Reply From: twinpixel

You could create a custom signal which gets called in _input(ev), followed by set_process_input(false), but that seems a bit complicated.

func _ready():
  set_process_input(true)
  add_user_signal("do_something")

func _input(ev):
  emit_signal("do_something")
  set_process_input(false)

and in your main function:

func yourfunc():
  do something
  do something
  yield(get_node("node_that_emits_signal"), "do_something")
  do_something_else

Note that you can use:

signal do_something()

func _ready():

Instead of:

func _ready():
    add_user_signal("do_something")

Bojidar Marinov | 2016-04-28 08:24

:bust_in_silhouette: Reply From: vonflyhighace2

I figured a solution to my own problem. The best route I found was to run a while loop in another thread polling for a value, leaving the main loop open and preventing stalls. This combined with the yield statement gave me the functionality I was looking for.