#can anyone help me what is return. that's the only thing i don't completely understand
1 messages · Page 1 of 1 (latest)
Return ends a function/script at that point
eg. if not this then return end
but can also return values as a result of the return
example script
Function ReturnTheNumberOne()
return 1
end
print(ReturnTheNumberOne)
this would print 1
return ends a function, you can return values to the code that called your code
example with ordering food
local function order(food)
return food
end
local food_item = order("spaghetti") -- example
print(food_item)
if you want to end a function you can do this
if condtion then return end
or just
return
replace the function with a value
example:
function add(a, b):
return a + b
print(add(1, 4))
it would print 5
ok
btw almost forgot to mention, if this is in a module script, it will return it to the script that called it
** You are now Level 1! **