Can a function have a value attached to it And if so how would you do that. I tried doing something like this
Function Example()
--Do Stuff
End
Print (Example)
And the output printed something about a table Followed by numbers and letters
Can a function have a value attached to it And if so how would you do that. I tried doing something like this
Function Example()
--Do Stuff
End
Print (Example)
And the output printed something about a table Followed by numbers and letters
Yes, a function has a return statement. Note M39a9am3R's changes before doing this. What return will do, is return a value that you can either print or store in another variable
function Example()
local a = 5+3;
return a; -- we are returning the variable we just made
end
--you can do this
print (Example())
--or store it in another var
local OtherA = Example();
--You can return any types you want, whether it be CFrame values, Strings, decimals, integers, ect.
EDIT: Printing a function itself is about as useful as printing a Table. That is to say, not at all.
thank you
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Lua is case sensitive, so "Function" needs to be "function", "End" needs to be "end", and "Print" needs to be "print".