G.pcall
From GMod Wiki
Function | |
Syntax |
pcall( Function fFunc, Var vArg, ... ) Where is this used? |
Description: | |
Literally protected call. Calls the function with the listed arguments, if it fails, the error message can be brought up. The code still gets called after this, even if pcall returns false. | |
Returns: | Boolean , Var , ... |
Part of Library: | Global Functions |
Realm: | |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=G.pcall]G.pcall [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Examples
Additional Notes
- This function returns at least one value. The first value is a "success" Boolean that will be true if the function called with no errors, and false if there were errors calling the function.
- If the Boolean is true, whatever the pcall()ed function returned will follow it. So if a function that returns "Hello" and "World" is called successfully, pcall returns the following:
true, "Hello", "World"
- If the Boolean is false, the second return value will be a string containing the error text. Note that when a function is pcall()ed, errors are not reported. You will have to have to report the error yourself if you so choose to.
- ... means "limitless things like the last one". In other words, you can add more than one argument to pcall the same way you added the first one. The same goes for return values; as stated earlier, pcall can return as many arguments as necessary.