I have seen return in a few scripts and I don't quite get what it does. I have looked it up in the wiki but I don't quite get it. Can someone explain it to me?
✓ ANSWER ACCEPTED
Can someone explain Return to me?
1 answer
✓ Accepted answer
Return is applicable in many ways. You can get values on a long formula, but you only have to type in the formula once. For example:
Instead of
x = math.sqrt(math.pow(3 ,2) + math.pow(4 ,2))
y = math.sqrt(math.pow(6 ,2) + math.pow(12 ,2))
print(x)
print(y)
You can simplify that into one function:
x = 3
y = 4
p = 6
q = 12
function PT(a, b) -- Pythagorean Theorem
Answer = math.sqrt(math.pow(a, 2) + math.pow(b, 2))
return Answer
end
print(PT(x,y))
print(PT(p,q))
Of course, there are other useful things to do with return, but this is just one example.
The gist is that you're literally converting a function into a value.
Take note that a return statement immediately stops the function, so anything besides ends after it will error out.
2 comments
0
Oh. I guess that makes sense! Thanks!
1
You're welcome.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Have you looked at the Wiki? http://wiki.roblox.com/index.php?title=Function#Using_Return