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: What's better to use? coroutine or spawn?

Previous Thread :: Next Thread 
NeonDolphin37 is not online. NeonDolphin37
Joined: 24 Dec 2013
Total Posts: 895
05 Nov 2016 03:29 PM
They both essentially do the same thing
I like spawn because its less words but
Is it ever more advantageous to use coroutines?
Report Abuse
expoundings is online. expoundings
Joined: 02 Feb 2013
Total Posts: 2359
05 Nov 2016 03:32 PM
in my experience I prefer spawn
however that's because I'm rather bad with coroutine, coroutine probably has advantages
Report Abuse
lua_pointer is not online. lua_pointer
Joined: 15 Oct 2016
Total Posts: 179
05 Nov 2016 03:33 PM
Coroutines are useful because technically spawn doesn't start the thread immediately, while a coroutine does. You'll never run into an issue using spawn though; I simply prefer the more complex look of coroutines, and the easy yielding methods.
Report Abuse
RubyEpicDragon is not online. RubyEpicDragon
Joined: 02 May 2015
Total Posts: 1211
05 Nov 2016 03:35 PM
What iscoroutine? Someone explain I never heard about it so please don't make fun of it.
Report Abuse
RubyEpicDragon is not online. RubyEpicDragon
Joined: 02 May 2015
Total Posts: 1211
05 Nov 2016 03:35 PM
What is coroutine? Someone explain I never heard about it so please don't make fun of it.
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
05 Nov 2016 03:36 PM
coroutines create threads that can be resumed and yeilded but will run without yeilding your current thread
Report Abuse
Intended_Pun is not online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
05 Nov 2016 03:37 PM
@Ruby
http://wiki.roblox.com/index.php?title=Global_namespace/Coroutine_manipulation
Report Abuse
NeonDolphin37 is not online. NeonDolphin37
Joined: 24 Dec 2013
Total Posts: 895
05 Nov 2016 03:40 PM
Never knew spawn had a slight delay

@Wunder I didn't understand your explanation, and I KNOW what coroutines are.
Use simpler words lmao

@Ruby
A script normally runs from top to bottom, and it wont start the next line(s) until you are finished running your current line(s)
So if you have one while loop in the script, it will never go on until the entire while loop is finished.
coroutines let you go by that. If you have a while loop inside a coroutine, you can run the loop AND the line after the coroutine, and the line after that, and on.

It sort of creates a small second script inside your script that you can run at the same time.
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
05 Nov 2016 03:43 PM
Yeilding means to pause or stop

an example here

print("hi")
wait(1 )--yeilds thread until waiting is done
print("yay")

coroutine.wrap(function() --new thread
wait(1 )--yeilds thread until waiting is done
print("yay")
end)()
print("hi")
Report Abuse
RubyEpicDragon is not online. RubyEpicDragon
Joined: 02 May 2015
Total Posts: 1211
05 Nov 2016 03:47 PM
Will it cause more lag or ask the server or players device to work harder or something?
Report Abuse
lua_pointer is not online. lua_pointer
Joined: 15 Oct 2016
Total Posts: 179
05 Nov 2016 03:50 PM
@Ruby
Today's devices are immensely powerful, as long as you code efficiently you will never have issues.

@OP
"Never knew spawn had a slight delay"
It's something to do with the thread scheduler I believe, it waits for the next tick or something, I'm not sure how it works _at all_. I just remember being told that by DR01D3K4 or whatever, the old programmer who used to visit here.

You'll never notice it, like I said.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
05 Nov 2016 04:34 PM
"You'll never run into an issue using spawn though"

You will actually if you use it in the game.OnClose callback.



@OP

Really if what you want is to "run multiple things at the same time" it doesn't matter. It is all coroutines behind the scenes.


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