mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Sep 2012 09:39 PM |
Explain coroutines to me? I get the basic concept (sorta? o.O) But why not just call the function? Only answer I can think of is that you can stop a coroutine. |
|
|
| Report Abuse |
|
|
|
| 29 Sep 2012 09:41 PM |
| http://wiki.roblox.com/index.php/Coroutines |
|
|
| Report Abuse |
|
|
1pie23
|
  |
| Joined: 11 Jul 2010 |
| Total Posts: 1865 |
|
|
| 29 Sep 2012 09:41 PM |
My personal favorite coroutine: delay.
function lol()
wait(10)
print("Hi")
end
delay(0, function() lol() end)
print("Hehe")
output: Hehe
10 seconds later
output: Hehe Hi |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
| |
|
|
| 29 Sep 2012 09:47 PM |
| http://wiki.roblox.com/index.php/Beginners_Guide_to_Coroutines |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
| |
|
AIAdvance
|
  |
| Joined: 28 Sep 2012 |
| Total Posts: 18 |
|
|
| 29 Sep 2012 09:49 PM |
function Fun()print(":D")end -- Just a simple function CoCre = coroutine.create(Fun) -- Renames & turns Fun into a coroutine coroutine.resume(CoCre) -- Runs the coroutine print("Win")
There Win would print after :D but only because Win's print was mentioned after the coroutine resume, but they both played at the same time, if you were to add wait(1) before print(":D") Win would print first.
Coroutines basicly take all the code inside the function, and run it seperately, and you'll probably most commonly see it used like
coroutine.resume(coroutine.create(function() -- Code end))
Just because most people don't call coroutines more then once, 'cause they're mostly used for multiple loops (At least that's why I use them.)
Also good for script/ commands in admin so you can run loops in them without messing anything up.
If code inside a coroutine errors, the script will still continue, since coroutines basicly create their own scripts.
Any questions? |
|
|
| Report Abuse |
|
|
| |
|
AIAdvance
|
  |
| Joined: 28 Sep 2012 |
| Total Posts: 18 |
|
|
| 29 Sep 2012 09:50 PM |
| Lol... I took so long to type that there's now 7 replies above it xD |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Sep 2012 09:52 PM |
@AI, Ty for taking time to write that, if there's something on the page that I don't understand, I'll ask you :P |
|
|
| Report Abuse |
|
|
AIAdvance
|
  |
| Joined: 28 Sep 2012 |
| Total Posts: 18 |
|
|
| 29 Sep 2012 09:53 PM |
You're welcome :P Think you can solve my problem on global functions? x3 |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Sep 2012 10:01 PM |
@AI, wat? :3 You mean _G? _G["printfunc"] = (function (string) print(tostring(string)) end)
In another script: _G.printfunc(stuff)
I think :o Only studied _G once, that was like, 2 months ago maybe o.O |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Sep 2012 10:03 PM |
Disregard my last question x3 I didn't read your thread, I thought you just had a spontaneous question :P |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Sep 2012 10:09 PM |
Not question >:O I meant "Disregard my last post" |
|
|
| Report Abuse |
|
|
AIAdvance
|
  |
| Joined: 28 Sep 2012 |
| Total Posts: 18 |
|
| |
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 29 Sep 2012 10:15 PM |
| How is coroutines difficult to understand? I got it in a heart beat... |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Sep 2012 10:17 PM |
@Miz, So because you can do it means it's easy for everyone...? Also, the original wiki page didn't explain a lot, the beginners guide is a lot better. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 29 Sep 2012 10:34 PM |
No, I did not say that. It's just that I don't see why it's an advanced topic to learn. Really easy for me. So I don't get how it's hard for you...
What don't you understand? Which coroutine you don't get? I'll explain it. |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Sep 2012 10:36 PM |
@Miz, I understand it now, The coroutine's page just doesn't have enough information for what I want to do. |
|
|
| Report Abuse |
|
|
|
| 29 Sep 2012 10:39 PM |
| HOORAH! Random post #1. You mad readers? Lolololol. |
|
|
| Report Abuse |
|
|