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

printing a function?

Asked by 8 years ago

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

2
Lua is case sensitive, so "Function" needs to be "function", "End" needs to be "end", and "Print" needs to be "print". M39a9am3R 3210 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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.

0
thank you Frandavi1000 15 — 8y
Ad

Answer this question