Returning

Learn what is returning and how to use it!

by Bloker_therd1226

Author Avatar

Introduction:

Returning is used to to send informations back to where the function is called. It's very easy, after reading this tutorial you will understand it.

How to use it?

Here, I'll give an example of its usage:

function testReturn()
    return "This is a test!"
end

So what would it do is it returned the value that it returned, in this case it's "This is a test!" since it's the value I returned. You might ask, what does it do? Let me print it so I can show you.

local returnedValue = testReturn() -- We've called the function, necessary for the functions to work.
print(returnedValue)

You might ask, why did I print the function? Well it's not the function I printed, it's the value of I have returned. Here is the output:

This is a test!

Yes, if you test it out it will print the returned value. Because it's used to send informations to where the function is called. Here is the final code:

function testReturn()
    return "This is a test!"
end

local returnedValue = testReturn ---- We've called the function, necessary for the functions to work.
print(returnedValue)

I will give another example.

function multiply(x, y)
    return x*y
end

local returnedValue = multiply(5, 4)
print(returnedValue)

20

That is returning! I hope you understood what returning is, it's very easy and test it out!

View in-game to comment, award, and more!