generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: coroutines

Previous Thread :: Next Thread 
Alimegacorn is not online. Alimegacorn
Joined: 24 May 2013
Total Posts: 899
08 Aug 2016 08:34 AM
what are they and how can they be helpful?

much thks
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
08 Aug 2016 08:36 AM
They are what allow multiple scripts to seem like they are running at the same time.
Report Abuse
Alimegacorn is not online. Alimegacorn
Joined: 24 May 2013
Total Posts: 899
08 Aug 2016 08:37 AM
can you tell me how they can be useful?
am too lazy to look it up
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
08 Aug 2016 08:38 AM
coroutines allow for multiple threads to run on the same script

usually, in 1 script, only 1 thing can be done at a time and the whole script yields for every wait()

with a coroutine, you can have 2 threads running at once without having to create to scripts

for example, you could have two while loops running at the same time, whereas in a normal script without coroutines, you can't do this
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
08 Aug 2016 08:39 AM
Spawn() and Delay() are what I use because they create new threads but they are way easier than coroutines, but coroutines are a bit more powerful.

They are useful for running functions that yield without yielding the script, running two loops at once, and other stuff
Report Abuse
Alimegacorn is not online. Alimegacorn
Joined: 24 May 2013
Total Posts: 899
08 Aug 2016 08:39 AM
oh wow

theres been so many situations where i wish they added this functionality
much thanks
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
08 Aug 2016 08:43 AM
Spawn, Delay, coroutines, etc. do not create actual threads, it's all done via collaborative multi-threading. One coroutine (Spawn and Delay create coroutines) is ever running at once time.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
08 Aug 2016 08:43 AM
It is all coroutines.
Report Abuse
Alimegacorn is not online. Alimegacorn
Joined: 24 May 2013
Total Posts: 899
08 Aug 2016 08:45 AM
oh lel
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
08 Aug 2016 08:50 AM
But yes it gives the appearance of things happening at the same time.
I remember using a Ceramic example a long time ago, something along the lines of like:

Without coroutines:
- Wedge Clay 1
- Form Clay 1
- Fire Clay 1
- Wait
- Glaze Clay 1
- Fire Clay 1
- Wait
- Repeat for Clay 2 -> Clay 5

With coroutines:
- Wedge Clay 1
- Form Clay 1
- Fire Clay 1
- Repeat for Clay 2 -> Clay 5
- Glaze Clay 1
- Fire Clay 1
- Repeat for Clay 2 -> Clay 5

So pretty much, instead of "waiting" you could be more efficient by doing other things. Of course the above example is stupid but I mean I hope it gets the point across.
Report Abuse
Alimegacorn is not online. Alimegacorn
Joined: 24 May 2013
Total Posts: 899
08 Aug 2016 08:54 AM
it sure does
thanks for the help guys!
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
08 Aug 2016 09:28 AM
coroutines are similar to spawn

usually the most useful uses are only

coroutine.wrap(function()

end)()

and

spawn(function()

end)

These both will run whatever is inside as if you ran it in a different script except coroutine.wrap() returns a function which resumes that coroutine so calling it with () will resume it.

The reason why this is one of the only useful ways is because in functions you can always just do
function DoSomething = coroutine.wrap(function()

end)

to create a function that acts like a coroutine
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
08 Aug 2016 09:35 AM
urdumb
Report Abuse
pketny is not online. pketny
Joined: 27 Dec 2010
Total Posts: 1162
08 Aug 2016 09:38 AM
http://wiki.roblox.com/index.php?title=Function_dump/Functions_specific_to_ROBLOX#Spawn

'Executes function f after thread next yields.' - Spawn will not run until the current script waits for something (wait() is called or WaitForChild())

Be careful when using Spawn().

coroutine will run instantly:

http://wiki.roblox.com/index.php?title=Function_dump/Coroutine_manipulation

Example why you have to be careful:

http://wiki.roblox.com/index.php?title=Thread_scheduler


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image