Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Starting time for each timer
- --# You could add more, but you'd have to add a bit of code to 'printTime' to dipslay them
- local timers = {
- {"10","00"},
- {"5","00"}
- }
- --# Returns tTime in a xx:xx format
- local function formatTime(tTime)
- return tTime[1]..":"..tTimer[2]
- end
- --# Decrements each timer
- local function updateTime()
- local allDone = true
- for i = 1, #timers do
- if timers[i][2] == "00" then
- if tonumber(timers[i][1]) > 0 then
- timers[i][2] = "59"
- timers[i][1] = tostring(tonumber(timers[i][1]) - 1)
- allDone = false
- end
- elseif tonumber(timers[i][2]) < 10 then
- timers[i][2] = "0"..(tonumber(timers[i][2]) - 1)
- allDone = false
- else
- timers[i][2] = tostring(tonumber(timers[i][1]) - 1)
- allDone = false
- end
- end
- return not allDone --# Returns 'true' if at least one timer counted down, false if all timers have finished
- end
- --# Prints time to monitor
- local function printTime()
- monitor.setCursorPos(1,6)
- monitor.clearLine()
- monitor.write(" T MINUS "..formatTime(timer[1]).."MINUTES")
- monitor.setCursorPos(1,10)
- monitor.clearLine()
- monitor.write(" T MINUS "..formatTime(timer[2]).."MINUTES")
- end
- --# Insert this in place of '-- TIMER HERE <<<<>>>>'
- --# The above functions just need to be somewhere above this, in the same program
- local timerID = os.startTimer(1)
- while true do
- local event = { os.pullEvent() }
- if event[1] == "timer" and event[2] == timerID then
- if not updateTime() then break end --# Stops when all functions have reached 0:00
- printTime()
- timerID = os.startTimer()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement