#New scripter
1 messages · Page 1 of 1 (latest)
return returns
so like
you could do
local a = 10
local b = 15
function add(num1, num2)
return num1 + num2
end
and while you'd never need to make an adding function
it's useful because it can return pretty much anything
local a = 10
local b = 15
function add(num1, num2)
return num1 + num2
end
local sum = add(a,b)
print(sum) -- prints "25"
print(add(a,b)) -- prints "25"
you could also do
local a = 10
local b = 15
function add(num1, num2)
local added = num1 + num2
return added
end
local sum = add(a,b)
print(sum) -- prints "25"
print(add(a,b)) -- prints "25"
pretty useful
used very commonly in OOP
because lua doesn't have built in classes, the (thing).new() method uses return to give the new object
like Vector3.new()
return just stops the function it's in and "makes it" into a value
function MyFunc()
return "hi"
end
print(MyFunc())
prints "hi"
nothing inside of the function after a value is returned will run
its other terms you send a code, u send a print statement and it sends back hello world for example and in this case you send a function and return hi