What is returning?

I’m trying to understand what returning is but every resource I’ve used hasn’t shown me anything. I’ve tried to look at a teleport video from CovertCode, use the AI assistant to help me in finding out what returning is, and I used several tutorials on returning but they all seem very different and I end up getting confused.

Questions:
-What is returning?
-Can returning be multiple things?
-Is it only used to change the result of a function after the function has happened?

answer to all 3 questions:
returning stops the function and gives it a value. it can be multiple things as it as it does 2 things

if you still dont understand this might help

local value = 3
local function hello()
if value == 3 then
return true
else
return false
end
end

if hello() then -- by doing if hello, it starts the function and waits for it to end or return, and once it returns, the value returned is either true or false as set previously, which then affects the if statement
print("value is equal to 3")
else
print("value is not equal to 3")
end

you might think that this isnt that useful, but if your checking many stuff at once and need multiple lines, its gonna make the code take less lines and look better

2 Likes

I see, so return sets the function hello to a value, depending on the value a certain event or series of events will happen. So returning is giving a function a value and based on that value you can do multiple things from there.

also remember that returns basically cancel a function as if the function was
function hello()
return true
print(1) – 1 wont be printed as return already canceled the function
end

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.