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
01function doClock(undif)
02    if debounce2 == false then
03        local undif = 0
04        local debounce2 = true
05        local DefaultTimeMinutes = mapStorage.DefaultTimeMinutes.Value
06        local MinutesLeft = DefaultTimeMinutes
07        local SecondsLeft = (MinutesLeft * 60) - 1
08        local MinutesLeft = MinutesLeft - 1
09        while SecondsLeft ~= 0 do
10            local SecondsLeft = SecondsLeft - 1
11            -- i wanna check if a minute passed, remove 1 from the minute value
12            wait(1)
13        end
14    end
15end

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.

01local minutesLeft
02local secondsLeft
03 
04function removeMinutes()
05      minutesLeft = minutesLeft - 1
06      print(minutesLeft.. " minutes and: " .. secondsLeft.. " seconds left.") -- Prints the time left
07end
08function removeSeconds()
09      secondsLeft = secondsLeft - 1
10    print(minutesLeft.. " minutes and: " .. secondsLeft.. " seconds left.") -- Prints the time left.
11end
12 
13function doClock()
14        local DefaultTimeMinutes = mapStorage.DefaultTimeMinutes.Value
15        local MinutesLeft = DefaultTimeMinutes
16        local secondsM = MinutesLeft * 60
17        delay(1, removeSeconds())
18        delay(60, removeMinutes())
19end

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