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

Can't functions be given a value? Like in this script?(it is not working xD)

Asked by 5 years ago
Edited 5 years ago
function Funct1()
    print("This is the first function")
end

function Funct2()
    print("This is the second function")
end

Adder() = 10   -- Why can't I give the function a number value like this?

function Adder()
    Funct1()
    wait(2)
    Funct2()
    wait(2)
    print("Holy moly this stuff gets confusing FAST")
end

repeat Adder() 

until Adder() == 11

0
Don't swear here.. User#20388 0 — 5y
0
Sorry, I will edit it out, but can u answer the question? hawkeye1940 8 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

The value never changes as the function never changes it. Not to mention the value is the same as the function after it.

function Funct1()
    print("This is the first function")
end

function Funct2()
    print("This is the second function")
end

Value = 10 --Value has to have a different name then the function. Adder() only fires the function, and since its before the function is named it wont work.

function Adder() 
    Funct1()
    wait(2)
    Funct2()
    wait(2)
    print("Holy #### this #### gets confusing FAST") --No swearing :-)
    Value = Value + 1 -- Changes the value
end

repeat Adder()

until Value == 11

Cant say I solved your problem but I tried what I could.

0
Thanks hawkeye1940 8 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Functions can return a value which then you can assign that value to a variable.

For example:

local function getNumber(x)
    if type(x) == "number" then
        return x
    end

    return 0
end

-- set a variable to a number returned by
-- the function
local num = getNumber(54)

-- num now will equal 54 because the function
-- returns a number type value which we passed 54
0
So you can make Adder return 10 at the bottom of the function if you want to make the function return the value of 10 Impacthills 223 — 5y

Answer this question