Dinizterz
|
  |
| Joined: 08 Oct 2008 |
| Total Posts: 4193 |
|
|
| 03 Oct 2013 05:57 PM |
It's always been on my mind, it could be just a simple line of code, but after some research I can't seem to find it. What I'm looking for is to stop a function while it's running. I looked at coroutines for this, but it seems that the coroutine function can only be stopped if the "coroutine.yield" is INSIDE the coroutine function. I think I'm misunderstanding coroutines, but the goal is to stop a function in its path. Something along the lines of this:
function soar() wait(1) print("take off") wait(1) print("soaring") wait(1) print("still soaring") wait(1) print("done soaring.") end
soaringbool.Changed:connect(function() if soaringbool.Value == true then soar() else [STOP THE SOAR FUNCTION] end end)
I want to know because my current method is to clone a script with a function when a boolvalue is true, and when the boolvalue turns false which could be in the middle of the cloned script's function, the cloned script is destroyed, alternatively stopping a function in it's path. How do you do it in a more efficient way? Coroutine.yield? A function manipulation i'm missing? Thanks.
|
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 03 Oct 2013 06:03 PM |
| I think it's "break (function)" but I haven't used this so I wouldn't know. |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2013 06:26 PM |
U could also use a variable in the funtion that checks if its true
♫♪ repeat wait() until game.Players.FrozenSmite.HasALife == true ♪♫ |
|
|
| Report Abuse |
|
|
|
| 03 Oct 2013 06:45 PM |
| You can check if the BoolValue is still true within the function you made. |
|
|
| Report Abuse |
|
|
Dinizterz
|
  |
| Joined: 08 Oct 2008 |
| Total Posts: 4193 |
|
|
| 05 Oct 2013 08:58 PM |
| I've come to that method, xXxMonkey, but it seems way too inefficient. To make it look less ugly I could use a for loop. |
|
|
| Report Abuse |
|
|
Dinizterz
|
  |
| Joined: 08 Oct 2008 |
| Total Posts: 4193 |
|
| |
|
sam8985
|
  |
| Joined: 12 Nov 2011 |
| Total Posts: 582 |
|
| |
|
sam8985
|
  |
| Joined: 12 Nov 2011 |
| Total Posts: 582 |
|
| |
|