I add true to my return statement if I want to check how the called function returned, or ended.
When I have a return true, I only return true when everything ran as expected, any other path through the function, that isn’t as expected, will return false. [import]uid: 5317 topic_id: 9319 reply_id: 34058[/import]
Functions can give a result when they finish. Saying “return true” means the returned result is “true” whereas just saying “return” means there’s no result.
seth’s code demonstrates functions returning results from functions. At the very bottom try print(a) and print(everythingAlright) to see the results. [import]uid: 12108 topic_id: 9319 reply_id: 34125[/import]
Be careful as there is a subtle difference between “return” and “return nil”:
[lua]local f1 = function() return end
local f2 = function() return nil end
local f3 = function() return false end
local f4 = function() return true end
local ff = function(…) print(select("#",…),",",select(1,…),",", select(1,…)) end
ff(f1())
ff(f2())
ff(f3())
ff(f4())[/lua]
Which seems to imply that “return” truly doesn’t seem to return anything, which is different from “return nil”, where the latter returns a real nil. Most of the time that difference is not visible, unless you count argument-values with select.
Just one of those nasty nil-gotchas in Lua that can bite you when you don’t expect it…