Hey Developers! Im A Intermediate Scripter And I Want To Know What Is Return?/ How To Return A Function. Can You Explain Me In Comments
Returning within a function is basically sending a value to whatever called it, I guess.
For example, here is a (useless) function that adds to numbers for whatever reason:
local function add(num1, num2)
return num1+num2
end
local added = add(5,2) --any numbers
print(added) --7
Ok i really suck at explaining it, so here is the roblox article on it: https://education.roblox.com/en-us/resources/returning-values-from-functions
Return is a function to return values from functions/methods, it can also be used to immediately stop a function.
To return a function, you just return the function’s name (not a string) or the function itself, without calling it.
Examples:
local function B()
return 1
end
local function A()
print("Function A")
return B
end
print(A()()) -- 1
local function A()
print("Function A")
return function()
return 1
end
end
print(A()()) -- 1
Oh Im Understand Now! You Both Give Me A Solution
https://education.roblox.com/en-us/resources/returning-values-from-functions
Two official sources for you to learn from, best of luck!
Thank You For Your Feedback! I Already Read This But I Still Didn’t Understand It