0 votes

I am developing a Shoot 'em up with a spawn script for enemy waves. I spawn the enemies in a function "wave 1" called in _ready(). In this Wave-Spawn Function I create enemies with this line:spawn_enemy_group(type, amount, *time_between_enemies*, *time_after_spawning_all_enemies*)

In the spawnenemygroup-function I am using:
await get_tree().create_timer(time_between_enemies).timeout
after each enemy and
await get_tree().create_timer(time_after_spawning_all_enemies).timeout
after spawning all enemies

My problem is that the wave script will go on altough the timer in the spawn-function isn' t over yet. How can I make the wave-function wait until the timer in the spawn_enemy-function is over?

Godot version 4.0 stable
in Engine by (30 points)

This seems like the ideal use case for a signal, which you then yield on from the other function. For example, a finished_spawn_enemy signal.

2 Answers

0 votes

Here’s a quick guide on signals that might be helpful for you!

by (135 points)
+1 vote

Since you access the return value of get_tree().create_timer() on those lines only, they are local variables you can't access outside of the scope of your function.

You could a) write the created SceneTreeTimers into variables and await on them in different functions as well or b) use Timer nodes instead which might be a bit easier to reference in multiple places.

by (1,607 points)
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.