Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.wrap("back")
- local seconds = 0
- local minutes = 0
- local hours = 0
- local days = 0
- local filename = "counter_save.mag"
- function ticker ()
- while true do
- seconds = seconds + 1
- if seconds == 60 then
- seconds = 0
- minutes = minutes + 1
- os.remove(filename)
- file = io.open(filename, "w")
- if file != nil then
- file:write(minutes)
- file:write(hours)
- file:write(days)
- file:close()
- end
- end
- if minutes == 60 then
- minutes = 0
- hours = hours + 1
- end
- if hours == 24 then
- hours = 0
- days = days + 1
- end
- myString = tonumber(days) .. ":" .. tonumber(hours) .. ":" .. tonumber(minutes) .. ":" .. tonumber(seconds)
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("Accident free for")
- local x,y = monitor.getSize()
- monitor.setCursorPos(1 + math.ceil((x/2)-(myString:len()/2)), math.ceil(y/2))
- monitor.write(myString)
- sleep(1)
- end
- end
- function resetter ()
- while true do
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- term.write("Enter reset password:")
- local pwd = read("*")
- if pwd == "whoopsie" then
- break
- else
- term.setTextColor(colors.red)
- term.clear()
- term.setCursorPos(1,1)
- term.write("bad password")
- sleep(3)
- end
- end
- end
- --startup--
- file = io.open(filename, "r")
- if file != nil then
- minutes = file:read("n")
- hours = file:read("n")
- days = file:read("n")
- file:close()
- end
- --main--
- while true do
- parallel.waitForAny(ticker, resetter)
- term.setTextColor(colors.lime)
- term.clear()
- term.setCursorPos(1,1)
- term.write("password accepted, counter reset")
- sleep(3)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement