Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is coroutine used for and how do i make one?

Asked by 9 years ago

What is coroutine used for and how do i make one?

0
Just so you know: Coroutines are only infrequently the right choice BlueTaslem 18071 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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!

Ad
Log in to vote
1
Answered by 9 years ago

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.

Answer this question