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

What is "coroutine" for and what is it useful for?

Asked by 5 years ago

i never heard of coroutine and im just curios what it does, maybe it can help in the future

1 answer

Log in to vote
4
Answered by
Time_URSS 146
5 years ago
Edited 5 years ago

coroutine is used to run scripts at the same time (similar to creating a new script in workspace). if you had to run 2 functions at the same time, you could use them for example

coroutine.resume(coroutine.create(function()
    print("Hi")
end))

print("Hi")

They would print both at the same second.

There are more ways to use them, but this is a first way to know their job.

coroutine.create() makes a coroutine, in which you can place code.

coroutine.resume() runs the coroutine, like if you run a normal script by playing the game or pressing a button.

coroutine.wrap() acts like both above

coroutine.yield() yields (pauses/stops) the script

There are more uses for it and more corutine commands, if you want to know more go here: Beginners Guide to Coroutine

Ad

Answer this question