A quick dive into the concept of returning

I’m writing because it appears that many people are confused by this keyword, and I feel it is generally misunderstood. I hope by the conclusion of this you will have a better understanding of it. First lets look at how returning works

Example(1)

the variables numb1 and numb2 haven’t been exposed globally yet so they must be defined in the functions parameters if you plan on using them within the function body

local function Multiply(numb1,numb2)
return numb1 * numb2
end

Multiply(5,10) – the value of this is relative to the number this time it’s equal to 50

This works like foo1*foo2 = “number” you can use this in your code raw or you can choose to put it in a variable like this

Local value = Multiply(5,10) – same thing

example (2)

Local bool = function(ev) – the declaration of this variables existence within the said function
local ev = true – even though i used the local keyword i still need to use return to withdraw this value
return ev – withdraws the value from the function
end

warn(bool) – true gets printed in output or false depend on the one you put in

hopefully you were able to understand this because it can be very useful also this posted is aimed toward newer/amateur coders also don’t bother responding to this it’s just a guide

1 Like

Can you format the code properly? Example 2 won’t work, and makes no sense.

3 Likes

i would but I’m bad at formatting code also the second one works for me just don’t put the comments in

Formatted versions of code:

local function Multiply(numb1,numb2)
return numb1 * numb2
end

Multiply(5,10) -- the value of this is relative to the number this time it’s equal to 50
Local value = Multiply(5,10) -- same thing
Local bool = function(ev) -- the declaration of this variables existence within the said function
local ev = true -- even though i used the local keyword i still need to use return to withdraw this value
return ev -- withdraws the value from the function
end

warn(bool) -- true gets printed in output or false depend on the one you put in
2 Likes

thank god your a life saver man

sorry instead of bool do this instead bool() just a small mistake i made