Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to use Returns?

Asked by 10 years ago

Can someone explain returns to me plz? The wiki makes no sense to me.

1 answer

Log in to vote
3
Answered by
MrFlimsy 345 Moderation Voter
10 years ago

Returning is a way to get info out of a function. Let me give you an example:

function Add(a,b)
    return a+b
end

This will take two numbers and add them together, then return the result.

So if we do this:

Add(1,3)

Lua will read it as '4'

Here's a full example:

function Add(a,b)
    return a+b
end

print(Add(2,5)) --this will print 7

You can also return booleans and strings. Returning is useful for functions that 'check' whether something is true, or return a string based on user input.

0
"return" replaces where the function was called with whatever you put after the return statement. GoldenPhysics 474 — 10y
Ad

Answer this question