✓ Accepted answer
What I believe is happening is that ROBLOX's coroutine scheduler is immediately resumeing any Script threads that get yielded. 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.
1 comment
Thanks for the explanation, very much appreciated.