0 votes

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

Godot version 3.2.3
in Engine by (54 points)

1 Answer

0 votes

Infinite loops are bad. Using a timer is saver.

See https://godotengine.org/qa/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:
        yield(gettree().createtimer(build_missile_every_second), "timeout")

func start_missiles():
     build_missiles = true

func stop_missiles():
     build_missiles = false

Guess you have bodyentered/exited or similar event which calls start/stopmissiles.

by (642 points)
edited by

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

So it is not an infinite loop :-) I'll change my answer then using yield

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.