Can someone explain returns to me plz? The wiki makes no sense to me.
Returning is a way to get info out of a function. Let me give you an example:
1 | function Add(a,b) |
2 | return a+b |
3 | end |
This will take two numbers and add them together, then return the result.
So if we do this:
1 | Add( 1 , 3 ) |
Lua will read it as '4'
Here's a full example:
1 | function Add(a,b) |
2 | return a+b |
3 | end |
4 |
5 | print (Add( 2 , 5 )) --this will print 7 |
You can also return booleans
and strings
. Returning is useful for functions that 'check' whether something is true, or return a string based on user input.