I see returning a lot especially in functions, what does it do? Is it useful? Any explanation is appreciated.
✓ ANSWER ACCEPTED
Can someone help me understand what is returning, a good example?
2 answers
✓ Accepted answer
Returning is used to send informations back to where the function is called, here is an example:
local function sayHi()
return "Hi!"
end
-- Print returned value of sayHi
local returnedValue = sayHi()
print(returnedValue)
Here is the expected output:
Hi!
You can also return using integers, as well as performing arithmetics.
local function multiply(x, y)
return x*y
end
local returnedValue = multiply(5, 5)
print(returnedValue)
25
Returning is very simple and easy to learn and very useful.
You don't have to wrap in a variable print(multiply(5, 5))
Quick Recap: Returning is used to send informations to where the function is called, so whatever your returned value is, that value will get sent.
There's a really good Lua documentation page for exactly what you're looking for. https://www.lua.org/pil/4.4.html
1 comment
0
Thanks for help though
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Ah I get it! Thanks for help my friend!