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 » Scripters
Home Search
 

Re: How to use a coroutine multiple times while its running?

Previous Thread :: Next Thread 
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
27 Aug 2015 07:49 PM
im bad thanks for the help

im trying to do a cool fade animation thing while minimizing the lines and being efficient

thanks loves
Report Abuse
someonedie is not online. someonedie
Joined: 19 Mar 2011
Total Posts: 1710
27 Aug 2015 07:55 PM
I'm not exactly sure what you're asking but.

If you use delay(function, (waitTime)
end)

You can run multiple lines at the same time.

Example:
for i = 1, 2
delay(function, 0.25
print("YEP")
end)
end

You would see two Yep's pritned at the same time after 0.25 seconds.
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
27 Aug 2015 08:05 PM
Well the line of code would already be running in the coroutine
but i would want to start it again before it completes, but still have it complete what it was doing just be doing it twice same time

thank you for that other bit of code tho didn't know about it before
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
27 Aug 2015 08:13 PM
basically

local BorderPixelGrow = coroutine.create(function()
for i = 0, 90 do wait(.2)
brick[i].Transparency = .1
end
end
end
end)

local BorderPixelShrink = coroutine.create(function()
for i = 0, 90 do wait(.2)
brick[i].Transparency = .5
end
end
end
end)

coroutine.resume(BorderPixelGrow)
wait(.5)
coroutine.resume(BorderPixelShrink)
wait(.5)
coroutine.resume(BorderPixelGrow)

but wouldnt work because already running like a fridge
Report Abuse
someonedie is not online. someonedie
Joined: 19 Mar 2011
Total Posts: 1710
27 Aug 2015 08:16 PM
uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
27 Aug 2015 09:02 PM
?
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
27 Aug 2015 09:03 PM
but if i do


local BorderPixelGrow = coroutine.create(function()
for i = 0, 90 do wait(.2)
brick[i].Transparency = .1
end
end
end
end)

local BorderPixelShrink = coroutine.create(function()
for i = 0, 90 do wait(.2)
brick[i].Transparency = .5
end
end
end
end)

local BorderPixelGrow1 = coroutine.create(function()
for i = 0, 90 do wait(.2)
brick[i].Transparency = .1
end
end
end
end)

while 1 == 1 do
coroutine.resume(BorderPixelGrow)
wait(.5)
coroutine.resume(BorderPixelShrink)
wait(.5)
coroutine.resume(BorderPixelGrow1)
end

it would work perfectly
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
27 Aug 2015 09:14 PM
bump
Report Abuse
GhostSailor is not online. GhostSailor
Joined: 02 Jul 2010
Total Posts: 1913
27 Aug 2015 09:23 PM
local Mode = nil

local BorderPixelGrow = coroutine.create(function()
Mode = "Growing"
for i = 0, 90 do
wait(.2)
if Mode == "Shrinking" then break end
brick[i].Transparency = .1
end
end)

local BorderPixelShrink = coroutine.create(function()
Mode = "Shrinking"
for i = 0, 90 do
wait(.2)
if Mode == "Growing" then break end
brick[i].Transparency = .5
end
end)

coroutine.resume(BorderPixelGrow)
wait(.5)
coroutine.resume(BorderPixelShrink)
wait(.5)
coroutine.resume(BorderPixelGrow)

Lord of all things, breaded and unbreaded.
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
27 Aug 2015 09:25 PM
i want it to continue to grow tho the bricks ie 80 thru 99 and start up growing bricks 0 thru 99 again when started up at the same time, because bricks 0 thru 40 will be shrunk already by the second coroutine
Report Abuse
GhostSailor is not online. GhostSailor
Joined: 02 Jul 2010
Total Posts: 1913
27 Aug 2015 09:29 PM
local Mode = nil

local BorderPixelGrow = function()
Mode = "Growing"
for i = 0, 90 do
wait(.2)
if Mode == "Shrinking" then break end
brick[i].Transparency = .1
end
end

local BorderPixelShrink = function()
Mode = "Shrinking"
for i = 0, 90 do
wait(.2)
if Mode == "Growing" then break end
brick[i].Transparency = .5
end
end

spawn(BorderPixelGrow)
wait(.5)
spawn(BorderPixelShrink)
wait(.5)
spawn(BorderPixelGrow)

Lord of all things, breaded and unbreaded.
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
27 Aug 2015 09:31 PM
I don't want it to stop the current coroutine or function
just run another thread of it, like a clone or copy. so I can have 2 sets fading in and fading out at the same time
Report Abuse
GhostSailor is not online. GhostSailor
Joined: 02 Jul 2010
Total Posts: 1913
27 Aug 2015 09:35 PM
local BorderPixelGrow = function()
for i = 0, 90 do
wait(.2)
brick[i].Transparency = .1
end
end

local BorderPixelShrink = function()
for i = 0, 90 do
wait(.2)
brick[i].Transparency = .5
end
end

spawn(BorderPixelGrow)
wait(.5)
spawn(BorderPixelShrink)
wait(.5)
spawn(BorderPixelGrow)

Lord of all things, breaded and unbreaded.
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
27 Aug 2015 09:37 PM
That doesn't work because the first coroutine is already running by the time it is called upon a 2nd time

it works if I duplicate the local coroutine and name it something different and then call upon that
Report Abuse
GhostSailor is not online. GhostSailor
Joined: 02 Jul 2010
Total Posts: 1913
27 Aug 2015 09:48 PM
That's no longer coroutines. I'm spawning the functions instead.

Lord of all things, breaded and unbreaded.
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
27 Aug 2015 11:18 PM
But I want them to run at the same time
Report Abuse
GhostSailor is not online. GhostSailor
Joined: 02 Jul 2010
Total Posts: 1913
27 Aug 2015 11:32 PM
They do.

Lord of all things, breaded and unbreaded.
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
27 Aug 2015 11:33 PM
I thought functions ran the whole way through before continuing along in the script?
Report Abuse
lego555444 is not online. lego555444
Joined: 21 Sep 2008
Total Posts: 1383
27 Aug 2015 11:54 PM

try this

local BorderPixelGrow1 = function()
for i = 0, 90 do wait(.2)
brick[i].Transparency = .1
end
end
end)


for i = 1,3,1 do
wait(1)
spawn(BorderPixelGrow1 )
end
Report Abuse
GhostSailor is not online. GhostSailor
Joined: 02 Jul 2010
Total Posts: 1913
27 Aug 2015 11:59 PM
I used spawn(), which is similar to coroutines in that it's non-blocking.

Lord of all things, breaded and unbreaded.
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
28 Aug 2015 12:03 AM
but i want it to

1. Begin making all the bricks transparent (lets say it takes 10 seconds to complete)
2. Before all the bricks are made transparent, after 2 seconds, all of the bricks are made nontransparent again
3. all of the bricks start becoming transparent again (but before step 1 finishes or before step 2 finishes too)


Does anyone know if the delay function allows the script to continue down the thread or does it act as a wait?
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
28 Aug 2015 12:04 AM
ghost thanks for your help im a literal idiot and didnt realize you added spawn

i thought you were just calling the function :(

thx for putting up with me
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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