It’s time to settle this guys. And I don’t want no “each has its uses” cop-out. There can only be one!
I don’t think this create_timer example works, if it does it’s a very bad use since it’s being run every frame, thus creating timers every frame; avoid using await on per-frame functions.
func _process(delta: float) -> void:
visibility()
func visibility() -> void:
if visible:
await get_tree().create_timer(self.conceal_time).timeout
visible = false
if !visible:
await get_tree().create_timer(self.appear_time).timeout
visible = true
A more apt comparison may be to use recursion or a loop.
func _ready() -> void:
visibility()
func visibility() -> void:
while true:
var time: float = self.conceal_time if visible else self.appear_time
await get_tree().create_timer(time).timeout
visible = not visible
Any repeating timer should use a Timer Node, it’s rare for create_timer to be a good idea over Timer or a appropriate signal.
The example was made to be simple and easy to understand, even if it came at the expense of efficiency. Properly reflecting the order of operations that will also form the basis of the Timer nodes setup.
Also, using “while loops” is the definition of dangerous. Especially for newbies which is the target audience.
Still, the feedback and additional insight is highly appreciated. I may still use some of your suggestions in a future vid.
In his example. Yes.