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 » Scripting Helpers
Home Search
 

Re: Coroutine Confusion

Previous Thread :: Next Thread 
MidnightDeveloper is not online. MidnightDeveloper
Joined: 08 Feb 2014
Total Posts: 1671
06 Apr 2014 02:29 PM
Creative title, eh? No? ahaha.
Anyways, I have a problem with coroutines.
I was wondering how I could start a coroutine from the beginning instead of where it left off, without creating a new coroutine.
Report Abuse
velibor is not online. velibor
Joined: 24 Nov 2009
Total Posts: 1003
06 Apr 2014 02:43 PM
Use coroutine.wrap() instead of coroutine.create(), that returns a function where you can restart the coroutine with. And why don't you wish to recreate it again ?

Code
coroutine.create(coroutine.resume(function()
print('Hello world')
end))
Report Abuse
MidnightDeveloper is not online. MidnightDeveloper
Joined: 08 Feb 2014
Total Posts: 1671
06 Apr 2014 02:45 PM
I do not wish to create it again because I am going to be stopping the current coroutine when an event occurs, and I cannot create variable names with other variables so I would not know what coroutine to call. Thanks for the help, though! I'll try coroutine.wrap().
Report Abuse
velibor is not online. velibor
Joined: 24 Nov 2009
Total Posts: 1003
06 Apr 2014 02:51 PM
According to the luapil the next will happen :
'If a Lua thread (Coroutine) has been yielded and has been completly done, coroutine.resume() will restart the thread.'
Report Abuse
MidnightDeveloper is not online. MidnightDeveloper
Joined: 08 Feb 2014
Total Posts: 1671
06 Apr 2014 02:52 PM
Hold on, in your example you said coroutine.create, but in your statement you said to use coroutine.wrap. Which one is it?
Report Abuse
MidnightDeveloper is not online. MidnightDeveloper
Joined: 08 Feb 2014
Total Posts: 1671
06 Apr 2014 02:53 PM
And, I want to restart it from the start even when it's still running the code inside of the coroutine.
Report Abuse
velibor is not online. velibor
Joined: 24 Nov 2009
Total Posts: 1003
06 Apr 2014 02:56 PM
coroutine.create() will create a entire new Thread. This can't be called as a Function !
coroutine.wrap() will create a Thread that can be called as a function.

-- Example Coroutine.wrap()
function HelloWorld()
print('Hello')
end

local Func = coroutine.wrap(HelloWorld)

Func()
Func()

-- Yield then, and restart.

local Func

function Hello()
print('Hello world')
end

function HelloWorld()
Hello()
coroutine.yield(Func)
end

Func = coroutine.wrap(HelloWorld)

Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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