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

Is it possible to prevent errors in a looping round script with a giant pcall?

Asked by 5 years ago
Edited 5 years ago

If, in some bizarre case, you have a looping round script and it breaks, your entire game is on freeze. Forever! In that case, could you possibly wrap said round script in a giant pcallas follows?

function mainRoundSequence()
    while wait() do
        -- intermission
        wait(10)
        -- load map
        wait(5)
        -- load characters
        wait(30)
        -- round over
        wait(5)
        -- articulate the round stats, start over.
    end
end

while wait(1) do
    success, err = pcall(function()
        mainRoundSequence()
    end)

    if err then print(err) end
end

Again, would this script theoretically work to make your script "break-proof"? Thanks in advance.

1
couldnt it still hang on the error forever just continually restarting? i guess it depends what the issue is. DinozCreates 1070 — 5y
0
yeah what DinozCreates said, most errors won't fix themselves, it is best that they "freeze" it GoldAngelInDisguise 297 — 5y
1
You shouldn't call wait in the condition because it is hacky. It only works because it abuses the fact that numbers are truthy values, and wait returns a number. User#24403 69 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

While you could, you do not need to do this, and this does not make your scripts 100% break proof. pcall only catches runtime errors, so if you have syntax errors do not expect pcall to stop those. Syntax errors are what prevent your code from compiling in the first place. You should only wrap the bits that cause you problems in a pcall, and then fix them once you realise the error. And please do not call wait in your loop's condition.

0
Thanks, and I don't see why I *shouldn't* place a wait in my loop's condition laughablehaha 494 — 5y
Ad

Answer this question