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: Delay v Spawn v Coroutine.create/wrap?

Previous Thread :: Next Thread 
Solotaire is not online. 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 is not online. 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 is not online. 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 is not online. zins
Joined: 14 Jan 2011
Total Posts: 3394
01 Apr 2013 12:36 PM
[ Content Deleted ]
Report Abuse
Solotaire is not online. 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 is not online. coplox
Joined: 07 Jun 2008
Total Posts: 3252
01 Apr 2013 12:39 PM
I tend to use coroutines.
Report Abuse
patrline5599 is not online. patrline5599
Joined: 04 Dec 2008
Total Posts: 741
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 is not online. iStone4S
Joined: 07 May 2012
Total Posts: 416
01 Apr 2013 12:44 PM
What does this do, please?
Report Abuse
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
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 is not online. 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
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
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
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
01 Apr 2013 12:51 PM
Doesn't spawn wait a frame before running its code?
Report Abuse
Solotaire is not online. 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 is not online. 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 is not online. 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 is not online. 08C
Joined: 26 Jan 2013
Total Posts: 847
27 Aug 2013 12:40 AM
[ Content Deleted ]
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
27 Aug 2013 12:49 AM
[ Content Deleted ]
Report Abuse
nate890 is not online. 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 is not online. 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
MemoryAddress is not online. MemoryAddress
Joined: 20 Apr 2013
Total Posts: 1297
27 Aug 2013 06:59 AM
[ Content Deleted ]
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
27 Aug 2013 07:20 AM
I use delay. I could probably use spawn in most cases though.
Report Abuse
Maelstronomer is not online. Maelstronomer
Joined: 07 Jun 2008
Total Posts: 7649
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 is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
27 Aug 2013 09:28 AM
[ Content Deleted ]
Report Abuse
abaw7 is not online. 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
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
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
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