As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 06 Mar 2013 05:52 AM |
Hi [:[
How would I make a coroutine I can call more than once? I tried this:
--------------------------------------- local funcBody = function(a, b) _G.test = coroutine.wrap(funcBody) print(a, b, a == b) end)
_G.test = coroutine.wrap(funcBody) ---------------------------------------
Which didn't work. Awsh.
- As, my coroutine is flipping backwards! :O |
|
|
| Report Abuse |
|
|
|
| 06 Mar 2013 06:10 AM |
using spawn would be easiest.
Spawn(function) |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 06 Mar 2013 06:15 AM |
But then I can't use it like doing _G.test("arguments") D:
Since Spawn is... insta-execute!
- As, _G.haxFunction("As8D", "everybody") :O jk< |
|
|
| Report Abuse |
|
|
|
| 06 Mar 2013 06:20 AM |
Metatables, maybeh?
_G.Magic = setmetatable({},{__call = function() Spawn(function() print("LOL!") end) end})
_G.Magic() |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 06 Mar 2013 06:46 AM |
Ush. Is there a way I could incorporate a function in a script by ex. calling _G.test?
Script1: _G.test = function(a) a() end
Script2: _G.test(function() error("lulz") end)
> Script1 will crash if I'm right? D:
- As, game:service("Internet"):Open("http://www.roblox.com/My/Groups.aspx?gid=788808") |
|
|
| Report Abuse |
|
|
|
| 06 Mar 2013 10:20 AM |
local funcBody = function(a, b) _G.test = coroutine.wrap(funcBody) print(a, b, a == b) end)
_G.test = coroutine.wrap(funcBody) _____________________________________________
local co = coroutine.create(function(f, ...) while true do f(...) coroutine.yield() end end)
_G.test = function(f, ...) coroutine.resume(co, ...) end
Could try that. |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 06 Mar 2013 10:54 AM |
Hm, you can call the coroutine more than once, but passing arguments won't work. How bad you have to pass the arguments used for then next call of a coroutine in the yield function.
maybe there is some way to pass a coroutine to yield.... ?
- As, hallehøjska, jeg bliver kontaktet af rumvæsener! <<< Uhm, ok. |
|
|
| Report Abuse |
|
|
|
| 06 Mar 2013 11:14 AM |
local co = coroutine.create(function(f, ...) while true do f(a, b) f, a, b = coroutine.yield() end end)
_G.test = function(f, a, b) coroutine.resume(co, f, a, b) end
This works. :) |
|
|
| Report Abuse |
|
|
|
| 06 Mar 2013 11:15 AM |
local co = coroutine.create(function(f, a, b) while true do f(a, b) f, a, b = coroutine.yield() end end)
_G.test = function(f, a, b) coroutine.resume(co, f, a, b) end
THIS one works. Forgot to change my ... parameter to a, b. :C |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 06 Mar 2013 12:10 PM |
Ush. Spendid.
Though, I cannot make it error x_x. Also, I guess I have to find out what this f is.
----------------------------------------
local co = coroutine.create(function(f, a, b) while true do print(a, b + 1, a == b) f, a, b = coroutine.yield() end end)
_G.test = function(f, a, b) coroutine.resume(co, f, a, b) end
_G.test("function", 1, "a")
> Output: 1 a ----------------------------------------
- As, Use a cow-magnet on an UFO, please. |
|
|
| Report Abuse |
|
|
|
| 06 Mar 2013 12:40 PM |
'f' is a function. In your original example, seemed to want to pass a function to the coroutine. 'a' and 'b' are parameters to be passed on to function 'f' For example:
_G.test( print, 'Hello', 'World!' ) --> Hello World! |
|
|
| Report Abuse |
|
|
As8D
|
  |
| Joined: 24 Dec 2009 |
| Total Posts: 2907 |
|
|
| 06 Mar 2013 01:07 PM |
Ah.
I had some trouble with no output when I first entered the code in the Command Bar. Weird.
- As, _G.test(postComment, "I am a ziggy") |
|
|
| Report Abuse |
|
|