Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is there a way I can stop a spawn() (with a loop inside) from running anymore?

Asked by 6 years ago
Edited 6 years ago

I have a loop that spawns a new function each time it's ran, but I want to know if there's an easy way I can revoke that spawn() if it's not completed by the time the loop is ran again?

Example:


while wait(5) do print("yes") spawn(function() for i=1, 10 do wait(math.random(0,1)) print(i) end end) --The for i=1,10 has a 50% chance of completing itself before the while loop runs again, but I want to be able to cancel it so I don't have 2 spawn()s running over each other at once. end
0
wait() should NOT be your condition in while loops. User#19524 175 — 6y
2
Why not? Professor_Boxtrot 136 — 6y
1
That doesn't prove anything. I agree with Link saying it makes more sense to use `true` as the condition in a while loop. I do not agree with him stating that this is what is RIGHT, and moreover, using `wait` in the condition is WRONG. This is his preference, and truthfully both ways are fine. It doesn't affect the program in any way other than the yield initiating the loop*. Goulstem 8144 — 6y
1
I agree with goulstem, from what I've read it basically states that it is NOT okay, but it doesn't actually tell you why other than it being a "hack" (which it gives no evidence of this either) Professor_Boxtrot 136 — 6y

Answer this question