Set timer's wait time

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

I’m using a single timer that can spawn mobs & coins on a random location around my player.

How do I change the timer’s wait time 0.5s for mobs and then 5s for coins?

export (PackedScene) var mob_scene
export (PackedScene) var coin_scene

func _ready():

func _on_SpawnTimer_timeout():

var rng =

$Player/MobPath/MobSpawnLocation.offset = rng.randi_range(0, 6000)
var mob = mob_scene.instance()
var coin = coin_scene.instance()

mob.global_position = $Player/MobPath/MobSpawnLocation.global_position

coin.global_position = $Player/MobPath/MobSpawnLocation.global_position
:bust_in_silhouette: Reply From: jgodfrey

I’m not sure it makes sense to use a single timer to handle multiple events that should happen at different intervals. While you can certainly change a timer’s wait time (by setting it’s wait_time property), it’ll be more complex than necessary.

Based on your suggested time values, you could run a timer at a 0.5 second interval to spawn mobs and then spawn coins every 10th time the timeout even fires, but that’s pretty brittle and also unnecessarily complex.

I’d suggest that you use 2 timers - one for the mobs and one for the coins. That’s clean and simple.

Okie dokie

Thank you so much <3

Torvic | 2022-09-06 17:55