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

Whats "pcall" and how do I use it?

Asked by 5 years ago

The Roblox wiki doesnt provide enough detail on pcall

I know it has to do something with solving errors but that's all I know.

Can anyone explain how it works and how and when to use it?

0
pcall() is a function used to obtain the results of a function and return those results.. It obtains what the function returns and any errors that are in the function it is calling. DeceptiveCaster 3761 — 5y
0
This is not a question to ask here. This is a debugging website, not a code genertaing one. VVickedDev 54 — 5y
0
I don't really see how this generates code, the dude is just asking about a function, those questions are allowed here. User#22889 0 — 5y
0
VVicked, this is a question to ask how and what pcall is used for, if you think its a request then ill gladly escort you to the door. LoganboyInCO 150 — 5y

1 answer

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

In basics a pcall or protected call is a way of managing errors when scripting in Lua, and it works by catching any errors in the function inside it. The advantage of using a pcall is if an error is found in the script then the whole script will not be terminated, just the function that has an error.

For some extra info it is also a boolean which returns true if there are no errors and false if one pops up.

Here is the the Lua book to explain more about it and how it can be used:

https://www.lua.org/pil/8.4.html

There has also been a similar question asked on Scripting Helpers before with a great answer from ScriptGuider:
https://scriptinghelpers.org/questions/39638/how-does-pcall-xpcall-and-ypcall-actually-work

0
It returns everything that is a result of a function, not just a boolean. As I said in my other comment, it also returns the function's results and the error of the function (if there is one). DeceptiveCaster 3761 — 5y
Ad

Answer this question