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

How to do that if a minute passed, remove 1 from the minute value?

Asked by
Tabrix 2
4 years ago
function doClock(undif)
    if debounce2 == false then
        local undif = 0
        local debounce2 = true
        local DefaultTimeMinutes = mapStorage.DefaultTimeMinutes.Value
        local MinutesLeft = DefaultTimeMinutes
        local SecondsLeft = (MinutesLeft * 60) - 1
        local MinutesLeft = MinutesLeft - 1
        while SecondsLeft ~= 0 do
            local SecondsLeft = SecondsLeft - 1
            -- i wanna check if a minute passed, remove 1 from the minute value
            wait(1)
        end
    end
end

Any idea why on how to do that if a minute passed, remove 1 from the minute value? (as said on the comment)

0
So I used delay to not stop the entire script while waiting becuase you not only have to subtract seconds but minutes. bruno13bruno13 78 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Just add a delay() timer. When a certain time passes, an function will execute.

local minutesLeft
local secondsLeft

function removeMinutes()
      minutesLeft = minutesLeft - 1
      print(minutesLeft.. " minutes and: " .. secondsLeft.. " seconds left.") -- Prints the time left
end
function removeSeconds()
      secondsLeft = secondsLeft - 1
    print(minutesLeft.. " minutes and: " .. secondsLeft.. " seconds left.") -- Prints the time left.
end

function doClock()
        local DefaultTimeMinutes = mapStorage.DefaultTimeMinutes.Value
        local MinutesLeft = DefaultTimeMinutes
        local secondsM = MinutesLeft * 60
        delay(1, removeSeconds())
        delay(60, removeMinutes())
end

So what I just made it's use a function called "delay()" that when certain times passes (in seconds, first argument), then a callback will be fired, in this case the functions.

Hope it helped.

0
You don't need t print the time left, but it was just to prove the point to you. bruno13bruno13 78 — 4y
Ad

Answer this question