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: I call you, coroutine! Bambam!

Previous Thread :: Next Thread 
As8D is online. 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
ChuckTestaDotAvi is not online. ChuckTestaDotAvi
Joined: 03 Sep 2012
Total Posts: 439
06 Mar 2013 06:10 AM
using spawn would be easiest.

Spawn(function)
Report Abuse
As8D is online. 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
ChuckTestaDotAvi is not online. ChuckTestaDotAvi
Joined: 03 Sep 2012
Total Posts: 439
06 Mar 2013 06:20 AM
Metatables, maybeh?

_G.Magic = setmetatable({},{__call = function()
Spawn(function() print("LOL!") end)
end})

_G.Magic()
Report Abuse
As8D is online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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 is online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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 is online. 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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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 is online. 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
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