Solotaire
|
  |
| Joined: 30 Jul 2009 |
| Total Posts: 30356 |
|
|
| 01 Apr 2013 12:31 PM |
Which one do you guys find yourself using most often? What are the core differences between them, or are they all pretty similar--do any of them represent a separate thread better than the other? Are the run-times comparable?
Making this thread in part because I'd like to get your opinions and in part because there seems to be even less scripting discussion than usual. |
|
|
| Report Abuse |
|
|
Waffle3z
|
  |
| Joined: 15 Apr 2011 |
| Total Posts: 266 |
|
|
| 01 Apr 2013 12:32 PM |
Delay has a minimum 1-frame wait-time Spawn is easier to type coroutines have useful methods. |
|
|
| Report Abuse |
|
|
dekkonot
|
  |
| Joined: 22 Dec 2010 |
| Total Posts: 6685 |
|
|
| 01 Apr 2013 12:33 PM |
I honestly have no idea. I never use any of them, as I'm never in any large projects.
~Not a Moderator, The Makeshift Moderator Team, Dekkonot |
|
|
| Report Abuse |
|
|
zins
|
  |
| Joined: 14 Jan 2011 |
| Total Posts: 3394 |
|
| |
|
Solotaire
|
  |
| Joined: 30 Jul 2009 |
| Total Posts: 30356 |
|
|
| 01 Apr 2013 12:38 PM |
"I honestly have no idea. I never use any of them, as I'm never in any large projects." I find myself using them when trying to reduce the total number of scripts in my game, but mostly have used coroutines. |
|
|
| Report Abuse |
|
|
coplox
|
  |
| Joined: 07 Jun 2008 |
| Total Posts: 3252 |
|
| |
|
|
| 01 Apr 2013 12:43 PM |
i used a coroutine for having multiple loops instead of multiple scripts
is that the correct way? |
|
|
| Report Abuse |
|
|
iStone4S
|
  |
| Joined: 07 May 2012 |
| Total Posts: 416 |
|
|
| 01 Apr 2013 12:44 PM |
| What does this do, please? |
|
|
| Report Abuse |
|
|
|
| 01 Apr 2013 12:45 PM |
Coroutines don't create real threads, while delay and spawn do.
Delay should only be used when you actually don't want to run it immediately. Otherwise, use spawn. |
|
|
| Report Abuse |
|
|
Solotaire
|
  |
| Joined: 30 Jul 2009 |
| Total Posts: 30356 |
|
|
| 01 Apr 2013 12:48 PM |
"i used a coroutine for having multiple loops instead of multiple scripts
is that the correct way?"
If "multiple loops" means at the same time, then yes. |
|
|
| Report Abuse |
|
|
|
| 01 Apr 2013 12:49 PM |
@Solotaire
Use delay when you want to run it in a certain time. Use Spawn when you want to run something in another, real thread. Use coroutines when you just want multithreading. |
|
|
| Report Abuse |
|
|
|
| 01 Apr 2013 12:51 PM |
| Doesn't spawn wait a frame before running its code? |
|
|
| Report Abuse |
|
|
Solotaire
|
  |
| Joined: 30 Jul 2009 |
| Total Posts: 30356 |
|
|
| 01 Apr 2013 12:53 PM |
@iStone4S,
Here's an example of coroutines to help you understand
function printNumbers() for i = 1,3 do print(i) end end
routine = coroutine.wrap(printNumbers) routine() printNumbers()
that should give you something that looks about like this: >1 >1 >2 >2 >3 >3
If you didn't use a coroutine and just had the following: printNumbers() printNumbers()
Your output would be: >1 >2 >3 >4 >5 >6 |
|
|
| Report Abuse |
|
|
Snoxicle
|
  |
| Joined: 17 Nov 2012 |
| Total Posts: 187 |
|
|
| 01 Apr 2013 01:01 PM |
| I use spawn except for some cases where coroutines are needed. |
|
|
| Report Abuse |
|
|
HEAT507
|
  |
| Joined: 31 Aug 2012 |
| Total Posts: 429 |
|
|
| 01 Apr 2013 03:42 PM |
text=[[ print(1/1); ]] pcall(function() coroutine.resume(coroutine.create(loadstring(text)); end); |
|
|
| Report Abuse |
|
|
08C
|
  |
| Joined: 26 Jan 2013 |
| Total Posts: 847 |
|
| |
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 27 Aug 2013 03:45 AM |
| Coroutines have their own uses. It's best to use Spawn if you want to sneak a thread in there. Delay should only be used if you are trying to delay the thread from starting, otherwise it's best to use the Spawn function. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 27 Aug 2013 05:42 AM |
"because there seems to be even less scripting discussion than usual." No, usually there are 0-3 discussions per day. Yesterday everything suddenly changed, and scripters is filled with discussions.
And back on topic...
I use new threads just hacky stuff, so I could live without them, since they aren't useful for me at all. If you do everything clean and efficient, you shouldn't need new threads.
|
|
|
| Report Abuse |
|
|
| |
|
|
| 27 Aug 2013 07:20 AM |
| I use delay. I could probably use spawn in most cases though. |
|
|
| Report Abuse |
|
|
|
| 27 Aug 2013 08:53 AM |
Multithreading with .create vs new thread entirely - same difference? I use coroutine.resume(coroutine.create(function ...()) end)) because it is cool looking. |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
abaw7
|
  |
| Joined: 23 Oct 2009 |
| Total Posts: 745 |
|
|
| 27 Aug 2013 09:32 AM |
| I used to use coroutine.wrap(function() end)() because I understood Coroutines, and couldn't figure our how the heck Spawn worked. Then, I found out how Spawn worked, went Yay!, and that's my main choice now. |
|
|
| Report Abuse |
|
|
|
| 27 Aug 2013 09:47 AM |
I generally use spawn as its simple and does exactly what i need it to do. For example, having and entire model fade:
function fadeModel(model) for i,v in pairs(model:GetChildren()) do if v:IsA("BasePart") then Spawn(function() for i = v.Transparency*10,1,0.1 do wait() v.Transpareny= i/10 end end) end end end
~ I choice end)() coroutine.wrap(function() I and used Spawn Yay!, Spawn |
|
|
| Report Abuse |
|
|