Answered by
5 years ago Edited 5 years ago
It's actually a super simple concept.
When you return something in a function, that function just holds the value that it returned (Kinda like a variable would).
For example, if you did this:
There are tons of other things you can do with returning.
The basic idea though is that when you return something, the function holds that value.
No code will run after something is returned.
For example:
The second "Heyyy" wouldnt print, because the function ends at return.
Im also pretty sure Lua would throw an error if you tried to run code after a return, but don't quote me on that.
I'm sure there's someone that can explain it a LOT better than I can internally, because I'm not that good at knowing what goes on under the hood of it all.
In conclusion, when you return something within a function, the function basically takes that values reference in its place, sorta like a variable. You can also use returns as a similar solution to using break
with loops and such, since no code runs after you return something.