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

How do I make a function wait to execute until another function has finished before it?

Asked by
OniiCh_n 410 Moderation Voter
10 years ago

What method(s) do I use to make a function wait until another function has finished?

2 answers

Log in to vote
1
Answered by
User#2 0
10 years ago

Scripts are pretty linear. There's not often that you need to do something like this because a function will automatically wait for that function to finish until it continues. There is one way to do this, though, if needed.

local FuncDone = false

function f1()
    FuncDone = false -- Reset it in case of multiple calls
    Spawn(function() -- Start a new thread
        print("A")
        wait(3)
        print("B")
        FuncDone = true
    end)
end

function f2()
    f1()
    repeat wait(1/20) until FuncDone
    print("C")
end

f2()
Ad
Log in to vote
0
Answered by 10 years ago

You could have a function that returns true or false, and then have a repeat statement.

So for example:

function f1()
    if 1==1 then
        return true
    else
        return false
    end
end

function f2()
    f1()
    repeat wait() until f1
end

Answer this question