#New scripter

1 messages · Page 1 of 1 (latest)

versed arrow
#

Hello I’ve started to script and was wondering if anyone could give me some tips I’m a bit stuck on learning return n was js asking if anyone can give me advice on what to do

fervent ice
#

return returns

#

so like

#

you could do

#
local a = 10
local b = 15

function add(num1, num2)
    return num1 + num2
end

#

and while you'd never need to make an adding function

#

it's useful because it can return pretty much anything

#
local a = 10
local b = 15

function add(num1, num2)
    return num1 + num2
end

local sum = add(a,b)
print(sum) -- prints "25"
print(add(a,b)) -- prints "25"
#

you could also do

#
local a = 10
local b = 15

function add(num1, num2)
    local added = num1 + num2
    return added
end

local sum = add(a,b)
print(sum) -- prints "25"
print(add(a,b)) -- prints "25"
#

pretty useful

#

used very commonly in OOP

#

because lua doesn't have built in classes, the (thing).new() method uses return to give the new object

#

like Vector3.new()

dense valley
#

nothing inside of the function after a value is returned will run

versed arrow
#

ohhh okok

#

thanks guys

royal quail
# versed arrow ohhh okok

its other terms you send a code, u send a print statement and it sends back hello world for example and in this case you send a function and return hi