So, i know basically what coroutine.yield() does. I know it "pauses" a coroutine function, and picks up where it left off when called again. But I've seen this script that has "coroutine.yield()" on line 1 of their script, literally.
coroutine.yield() -- Script continues
Just curious, what does this do? Is this valid? What could it be used for? Thank you for taking the time to read this, hope you can help.
What I believe is happening is that ROBLOX's coroutine scheduler is immediately resume
ing any Script threads that get yield
ed. This sort of makes sense, since there's no way for any script you write to resume another script (there's no way to get the active coroutine).
The yield
is actually happening -- it's not just being ignored. I can tell because when I run these two scripts
print("a") coroutine.yield() print("b")
print("c") coroutine.yield() print("d")
I get
a c b d
as the output. This wouldn't be possible if coroutine.yield
didn't actually yield the thread.
You can yield
with a value. I wonder whether or not this corresponds to a builtin function like wait
. I couldn't get it to happen, though.
I can't imagine a reason for why you would do this. It might help with making sure other scripts "run" "before" this one, but that probably isn't very predictable.
It's definitely strange. I don't think it should be put to any use.