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

A quick question about Pcall?

Asked by 6 years ago
Edited 6 years ago

I seen in scripts they do something like

local success, message = pcall(function()

end

What does "success" mean and what does "message" mean? I don't see a clear explanation anywhere on what the first and second variables mean.

1 answer

Log in to vote
0
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
6 years ago
Edited 6 years ago

Protected Calls returns Boolean Values i.e true or false and the message.

When a Protected Call is initialized in the function, the pcall will catch that particular error and will return true if no errors were found and false if errors were found. Success is the variable that holds this Boolean Value. Do keep in find that pcall will immediately stop and return the error warning at the first error it sees. The pcall will not catch another error after the first error.

As for Message, pcall also returns what the error was. In this context, the Message is the error warning.

If the Success is true then the Message will be nil. Else, the Message will be the error warning.

0
Actually, if the function returns something, after the success bool, the return value(s) are there. hiimgoodpack 2009 — 6y
Ad

Answer this question