|
Let's say coroutine ABC is currently running and happens to have a loop that goes on forever.
How would I stop the coroutine--completely terminate it--from outside the function itself? |
|
nate890Join Date: 2008-11-22 Post Count: 21686 |
Can't you use coroutine.yield? |
|
|
Windows Task Manager.
-Brassrhino- |
|
|
Fun Fact: I don't know what the Hell I'm talking about.
-Brassrhino- |
|
|
ABC = coroutine.create(function()
while (true) do
wait(1)
print(time())
end
end)
coroutine.resume(ABC)
wait(1.5)
Now I need code here to terminate ABC. |
|
|
You could always remove the script with :Destory() |
|
nate890Join Date: 2008-11-22 Post Count: 21686 |
ABC=coroutine.create(function()
coroutine.yield(ABC)
end)
coroutine.resume(ABC) |
|
nate890Join Date: 2008-11-22 Post Count: 21686 |
Buddy, you can't stop the executing of code outside of a script. |
|
AltruistJoin Date: 2012-02-06 Post Count: 24 |
Why not just coroutine.yield(ABC)?
Technically it stops it. |
|
nate890Join Date: 2008-11-22 Post Count: 21686 |
Oh, "outside the function itself". No clue. |
|
AltruistJoin Date: 2012-02-06 Post Count: 24 |
blargh late post.
F L O O D C H E C K
K C E H C D O O L F |
|
gameheroJoin Date: 2007-06-12 Post Count: 1455 |
This is the only way I know how to do it.
request_stop = false
ABC = coroutine.create(function()
while (true) do
wait(1)
print(time())
if request_stop == true then
break
end
end
end)
coroutine.resume(ABC)
wait(3)
request_stop = true
print("Stop!!!!! >:O") |
|
iZ0mGeDJoin Date: 2011-06-10 Post Count: 128 |
O_o |
|
|
Why not try a variable?
able = true
ABC = coroutine.create(function()
while (able) do
wait(1)
print(time())
end
end)
coroutine.resume(ABC)
wait(1.5)
able=false |
|
|
I'd do it gamehero's way. I can't think of any other out-of-function way to do it. |
|
|
Does "coroutine.pause()" exists? Sorry I never use these. |
|
|
gamehero's way would have been the way for this BUT...
... the code is dynamic and could be anything.
I'm making a plugin that automatically executes scripts, but I need a button to terminate scripts too.
Therefore, I can't easily just insert variables into the already-existing source code like that. |
|
FlyScriptJoin Date: 2010-08-05 Post Count: 3008 |
I'd say remove it with a master script, or an 'if' event, if blah blah blah happens script.Parent.ABC:Remove() ABC would be the name of the coroutine script itself, in the same parent as the master script/script to destroy it. Infact, you could just have in the coroutine itself, if blahblahblah happnens, script.Remove or if you might want to run it later, :Clone(game.Lighting) and then put it in in a other place. if blahblahblah happens game.Lighting.ABC:Clone(game.Workspace) |
|
FlyScriptJoin Date: 2010-08-05 Post Count: 3008 |
BTW, love your games, mind promoting mine a little, seeing as I have been S-O-O-O-O helpful and all ;) |
|
|
nate890Join Date: 2008-11-22 Post Count: 21686 |
Gamehero's wouldn't stop the coroutine, it would stop the loop inside of the coroutine. coroutine.yield would suspend the coroutine. |
|
SDuke524Join Date: 2008-07-29 Post Count: 6267 |
> Therefore, I can't easily just insert variables into the already-existing source code like that.
Yes you can. |
|
|
SDuke, not really. The code could be anything, and there are multiple ways to keep a script going forever; not just loops. |
|
FlyScriptJoin Date: 2010-08-05 Post Count: 3008 |
Like I said, make the coroutine INSIDE s script itself, maybe use blahblahblha else end ? or you could have it as a loop, and make it run until a certain variable changes. e.g. have a boolean value and scriot like this:
b = game.Workspace.MyBoolean
while b true do
[INSERT COROUTINE HERE]
end
then ahve elsewear in the SAME SCRIPT.
if
such and such happens
b = false
end
That might work. |
|
nate890Join Date: 2008-11-22 Post Count: 21686 |
^A loop isn't associated with every coroutine. Most people posting here don't even understand the difference between coroutines and loops, and the difference is huge. |
|