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.
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.
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Actually, if the function returns something, after the success bool, the return value(s) are there.