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

When should I use pcall?

Asked by
Xternl 7
7 years ago
Edited 7 years ago

I get how pcall works, but I don’t get when I should use it.

2 answers

Log in to vote
1
Answered by 7 years ago

Use PCalls to handle things that could possibly error, such as datastores or Http requests, or if you're finding code doesn't work, you could do something like:

local success, err = ypcall(function()
    ppppppppppprint("i error!")
end)
if not success then
    print("Oops! I errored: " .. err)
else
    print("I succeeded!")
end
0
Thanks Xternl 7 — 7y
Ad
Log in to vote
0
Answered by
D3LTA_Y 72
7 years ago

This is a good tool for code errors, it is a good ally of a function if you want to keep track of what went wrong, you can use pcalls to keep track of your code carefully, putting one at each important step.

0
Thanks Xternl 7 — 7y
0
It slows everything down so no don't do it often. cabbler 1942 — 7y

Answer this question