This is really core to all programming, whichever language you’re using, so you might want to start off here:
http://www.lua.org/pil/contents.html
That site is simple and present clean examples.
Here’s the functions section: http://www.lua.org/pil/2.6.html
That may not help, if you’re new, so try to think of functions as “a series of instructions” which can be referred to by your code in just the same way that variables are referred to. The difference is that a function is not just a store for a value, it actually performs some logic, math, etc and gives you a value which is the result of that series of instructions.
And that’s what the return value is for. The value (or values) allows your function (series of logical instructions) to pass the final value of that logic back to your code.
You do not need to return a value from every function. For example, you might just have a function which prints something to the console display, so it does not need to return a value.
You can return more than one value, so if your function takes a table of integers and finds the highest and lowest numbers in the table, it can return both of those. I’ve written that below:
-- returns the highest and lowest values in the table passed in parameters local function getHighestAndLowest( numbers ) local lowest, highest = 0, 0 -- define the return values for i=1, #numbers do if (numbers[i] \< lowest) then lowest = numbers[i] end if (numbers[i] \> highest) then highest = numbers[i] end end return lowest, highest end -- call the function local lowest, highest = getHighestAndLowest( { 3,8,2,5,9 } ) print("Lowest: ",lowest) print("Highest: ",highest)
So, you can see that the function returns two values which you can then use later on. The reason the instructions in that function are in a function at all is because you might want to execute that code many times, so there is no point copying the instructions all over the place - this way you can just have the logic in one place and call it when you need it.
Now, returning true, false or any other value is just the same. There is no difference at all. They are values and return passes back values, that’s all.
Many people have trouble is knowing when to return true or false from touch listener functions, but that is a case-by-case specific situation. (For touch and tap functions you should return true if you have handled the user’s touch event, false if you haven’t.)
Let me know if you need a specific situation explaining - post some code and I’ll take a look.