How do I create an "infinite loop for" with dynamic typing

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

I would like to know how I can create an infinite FOR loop to instantiate every so long a missile for an indefinite time

:bust_in_silhouette: Reply From: clemens.tolboom

Infinite loops are bad. Using a timer is saver.

See https://forum.godotengine.org/9758/timer-node-how-to-use-it-in-code for some scenario’s (code or GUI)

Based on new comment (below) we will use yield().

var build_missiles :bool = false
var build_missile_every_second :float = 0.5

func do_build():
    while build_missiles:
        call_func_to_add_missile()
        yield(gettree().createtimer(build_missile_every_second), "timeout")

func start_missiles():
     build_missiles = true
     do_build()

func stop_missiles():
     build_missiles = false

Guess you have body_entered/exited or similar event which calls start/stop_missiles.

I’m not looking for a timer, I’m looking for the syntax to create a loop to indefinitely instantiate a missile every so long when an object enters an area

Peppe | 2021-07-29 17:32

So it is not an infinite loop :slight_smile: I’ll change my answer then using yield

clemens.tolboom | 2021-07-30 07:36