I was wondering if someone can explain to me what pcall
is used for, like what does it do?
Here's how to use pcall: (and of course its setup to fail....)
Change NILVALUE to "HI" for fail to be false and get the success message to print .
01 | local NILVALUE = nil |
02 | local success, fail = pcall ( function () |
03 | print ( "this is a test" ) |
04 | print ( "Concatenate a value: " ..NILVALUE) |
05 | end ) |
06 |
07 | if fail then |
08 | print ( "Failure: " ..fail) -- your failure reason will be here |
09 | return |
10 | end |
11 |
12 | print ( "we succeeded!!!" ) |
PCall Is a way to check errors in functions without breaking the script. This is widely used for debugging. It has 2 arguements, (true,error) if true is false then error message will be tjhe error in the script.