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

My coroutine for dialogue options won't work?

Asked by
XRed03 17
2 years ago

So I have some dialogue and I want two options: one you can press, and one that has a timer. I need to fit both in only one script, so I tried to use a coroutine to make the timer go while you're able to press the first button, but it won't work at all (proven with prints). does anyone know why? here is my code:

    coroutine.wrap(function()
    print("coroutine")
        for i=5, 1, -1 do
            wait(1)
            print(i)
            rightoption.Text = i
        end
    end)

Just for clarification,, the console outputs nothing.

2 answers

Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
2 years ago

Hello!

First of all, the coroutine.wrap() works with the parameter to be a function.

local value = 0

local function Test()
    print("coroutine")
    for i=5, 1, -1 do
        wait(1)
        print(i)
        value = i
    end
end

coroutine.wrap(Test)()

Here is the fixed code, you have to remove the value variable (I used it for testing). Also it isn't looping, if you wanted to do that.

0
It worked! Thank you! XRed03 17 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Adding on to SuperPuiu's explanation, you can wrap undeclared functions

coroutine.wrap(function()
    print("Coroutine")
end)()

To pass parameters, do:

coroutine.wrap(function(msg)
    print(msg)
end)("Coroutine")

Answer this question