|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 05 Nov 2016 03:37 PM |
@Ruby http://wiki.roblox.com/index.php?title=Global_namespace/Coroutine_manipulation |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|