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

Can I activate a function from inside another function?

Asked by
RoboFrog 400 Moderation Voter
9 years ago

Basically, I'm trying to make it to where a single function has 6 main parameters in which only one will activate, but they each also have more lines of code to go with each specifically. Since explaining it sounds confusing, here's a small example of what I'm talking about:

script.Parent.ClickDetector.HypoFunction:connect()

    if integerval.Value == 1 then -- activate function val1
    elseif integerval.Value == 2 then -- activate function val2
    elseif integerval.Value == 3 then -- activate function val3
    end
    end

    function val1()
integerval.Value = 10
end

    function val2()
integerval.Value == 20
end

Alright, so, thus far, this is very much hypothetical. I'm just curious if I could make it to where one of the elseif statements in "HypoFunction" could cause one of the "valX" functions to trigger, effectively making one function a control set for the rest?

I suppose I could do this by making other functions activate whenever a value changes, but this isn't exactly ideal for what I need it for. If that's the only way however, I can make it work. If there are any other ways, however complex, I'd gladly take a look.

If you need any more explanation, please let me know, as to I'd love to know if this "feature" is possible or not. Thank you for reading, and I appreciate any help!

1 answer

Log in to vote
1
Answered by
lomo0987 250 Moderation Voter
9 years ago
function val1()
integerval.Value = 10
end

function val2()
integerval.Value = 20
end

function val3()
integraval.Value = 30
end

script.Parent.ClickDetector.HypoFunction:connect()
    if integerval.Value == 1 then -- activate function val1
        val1()
    elseif integerval.Value == 2 then -- activate function val2
        val2()
    elseif integerval.Value == 3 then -- activate function val3
        val3()
    end
end

There you go :D This will work as long as it's activated and you have integerval defined.

0
Wow, that's much more simple than I expected. Thank you very much for the quick answer! RoboFrog 400 — 9y
1
No problem. If you need any more help just ask! :D lomo0987 250 — 9y
Ad

Answer this question