Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What does return do?

Asked by 8 years ago

So, I've noticed in some more, "advanced" code I've read through, there is an argument called return. I'm just starting out with Lua coding, I've asked friends but haven't really understood the function of the argument. Can someone clarify what "return" does?

1 answer

Log in to vote
3
Answered by 8 years ago

The return keyword is used in functions to send data back to the place where the function was called. Here is an example:

function divideBy(x,y) --initiate a function to divide x by y.
    return x/y --send the answer back to the place the function was called.
end
local division=divideBy(155,5) --division is now equal to 31!
print(division)

You can learn more about the return keyword here. I hope this helped!

Ad

Answer this question