of     1   

TheCrookMeister
#143427998Wednesday, August 13, 2014 12:23 AM GMT

coroutine.resume(coroutine.create(function() CODE end)) delay(0,function() CODE end) Are those two basically the same thing?
cntkillme
#143428177Wednesday, August 13, 2014 12:26 AM GMT

Basically, but I believe delay actually runs the function in an actual separate while coroutine simulates that.
IAmTheRolo
#143428362Wednesday, August 13, 2014 12:28 AM GMT

However, if all you're really trying to do is create a separate thread, I recommend Spawn
TheCrookMeister
#143428363Wednesday, August 13, 2014 12:28 AM GMT

Thanks! Which of the two do you prefer?
TheCrookMeister
#143428466Wednesday, August 13, 2014 12:29 AM GMT

Also, I just need to run some while loops without interrupting anything.
IAmTheRolo
#143428533Wednesday, August 13, 2014 12:30 AM GMT

Yeah, then use Spawn
cntkillme
#143428581Wednesday, August 13, 2014 12:30 AM GMT

I usually prefer coroutine since spawn and delay don't actually exist in Lua, but it was added by Roblox. So (depending on what I'm doing) if I ever want to work with something I made in RBX.Lua in Lua, I can be sure that coroutine will exist and is an actual data type as opposed to whatever roblox does.
cntkillme
#143428638Wednesday, August 13, 2014 12:31 AM GMT

Why not run the code in the while loops together?
Bobobob12
#143428639Wednesday, August 13, 2014 12:31 AM GMT

"However, if all you're really trying to do is create a separate thread, I recommend Spawn" i don't, since spawn passes arguments to the inner function; i say use coroutine.wrap(function())() for threads you don't need to stop manually
TheCrookMeister
#143429356Wednesday, August 13, 2014 12:39 AM GMT

@cntkillme I didn't know Spawn and Delay were Roblox-specific, haha. I only script inside of Roblox so far, so I'm not going to worry about that yet. Also, what do you mean run the code with the while loops?
cntkillme
#143429488Wednesday, August 13, 2014 12:41 AM GMT

Well it depends what you are doing, see if you can combine the two into 1 loop. It would be more efficient that way (if you can, of course)
islandmaker2012
#143429638Wednesday, August 13, 2014 12:43 AM GMT

func = function(args) local nW = coroutine.wrap(function(args) local Del = math.random(3) print("Waiting",Del,"Seconds to print",args) wait(Del) print(args) end) nW() end for I=1,5 do func(math.random(10)) end --XD? --ik cnt will show me up tho..
TheCrookMeister
#143429900Wednesday, August 13, 2014 12:46 AM GMT

I don't think I can do that. The main thread is based off of a while loop itself, and the other mini while loops don't run the entire time. Like this: local game = false local function dogame() delay(0,function() while (game) do GAME wait() end end) end local function game() game = true dogame() end local function endgame() game = false end while true do game() endgame() wait(5) end That wasn't as quick an example as I was hoping

    of     1