Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lalel345 |
I want to stop print with yield()
func _physics_process(delta):
example()
func example():
print("something")
yield()
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lalel345 |
I want to stop print with yield()
func _physics_process(delta):
example()
func example():
print("something")
yield()
Reply From: | scrubswithnosleeves |
I think you are looking for this:
yield(get_tree().create_timer(5.0), "timeout")
Where the float passed to the create_timer()
function is the amount of time that will be yielded. BUT BE CAREFULL WITH THIS. If you change scenes while this is yielding, it will crash your game in release. I think they are planning on fixing this in Godot 4.0, but for now, be aware of it.
If you want to yield for one or more physics frames, I think it’s best to just use a counter.
var counter = 0
var frames_to_wait = 1
func _physics_process(delta):
if counter >= frames_to_wait:
'do something'
counter += 1
Finally, if these don’t answer your question, check out the docs on using the yield function:
I want to stop and print once
lalel345 | 2020-12-08 17:40
oh haha, just use a flag:
var has_run = false
func _physics_process(delta):
if !has_run:
has_run = true
example()
func example():
print("something")
yield()
scrubswithnosleeves | 2020-12-08 22:54