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

How to stop a function from continuing?

Asked by 5 years ago
Edited 5 years ago

I was planning that my seed script project can have a line of code that can stop a function from continuing. Sorry this description is stub. But anyways to pause a function?

0
Functions will stop after it completes its task. Did you mean a loop? You can use "break" inside the loop. Bilinearly 58 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Assuming this is just for debugging and you still have code afterwards, you can do

local function foo()
    print("hello")
    do
        return
    end
    print("world")
end
foo()

and that will only print hello.

The reason this works is because return only needs no more code after it in its scope.

Hope this helps!

Ad

Answer this question