What is coroutine used for and how do i make one?
✓ ANSWER ACCEPTED
What is coroutine used for and how do i make one?
2 answers
✓ Accepted answer
Here, read this thread from the Roblox WIKI, and it'll explain, also sorry that I didn't type out an explanation, but I don't know how to explain what they do. :P;
http://wiki.roblox.com/index.php?title=Coroutines
Hope this helped!
It's as if the script were saying, "Go on, I got this."
When you create a coroutine, it creates another thread, inside this thread you will have your code, whatever it may be. However, while this code is running inside the coroutine, the script continues on and runs the rest of the script. For example:
coroutine.wrap(function()
while wait(1) do
print("Hi, I'm doing my own thing!")
end
end)()
print("Bye, I'm off to more important things!")
And that would print, "Hi, I'm doing my own thing!" once every second, but also print, "Bye, I'm off to more important things!" at the same time.
Hope that helped.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Just so you know: Coroutines are only infrequently the right choice