Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("button")
- rednet.open("right")
- m = peripheral.wrap("top")
- local clockComputers = {}
- local timerPaused = false
- local minTime = 30
- local secTime = 0
- local min
- local sec
- function mainMenu()
- m.clear()
- button.label(11,1,"Welcome to WRENCHED!")
- button.setTable("Start Timer",startTimer,"",3,18,6,8)
- button.setTable("Pause Timer",pauseTimer,"",22,37,6,8)
- button.setTable("Reset Timer",resetTimer,"",3,18,12,14)
- button.setTable("Edit Timer" ,editTimer ,"",22,37,12,14)
- button.screen()
- end
- function startTimer()
- timerPaused = false
- button.flash("Start Timer")
- button.setButton("Pause Timer", false)
- runTimer()
- end
- function pauseTimer()
- button.toggleButton("Pause Timer")
- timerPaused = not timerPaused
- if not timerPaused then
- runTimer()
- end
- end
- function resetTimer()
- timerPaused = true
- button.toggleButton("Reset Timer")
- findClocks()
- button.setButton("Pause Timer", false)
- button.toggleButton("Reset Timer")
- min = minTime
- sec = secTime
- sendTime()
- end
- function editTimer()
- timerPaused = true
- button.toggleButton("Edit Timer")
- findClocks()
- button.setButton("Pause Timer", false)
- button.toggleButton("Edit Timer")
- min = read()
- sec = read()
- sendTime()
- end
- function findClocks()
- rednet.broadcast("IsClock")
- doneClocks = false
- while not doneClocks do
- local id,msg,dist = rednet.receive(0.25)
- if not id then
- doneClocks = true
- else
- print("Clock Found: "..id)
- clockComputers[#clockComputers+1] = id
- end
- end
- end
- function sendTime()
- local data = {}
- data["min"] = min
- data["sec"] = sec
- msg = textutils.serialize(data)
- --print("Sending: "..msg)
- for id = 1,#clockComputers do
- --print(id)
- rednet.send(clockComputers[id],msg)
- end
- button.label(10,3, "Time Remaining: "..string.format("%02d:%02d",min,sec))
- end
- function runTimer()
- while min >=0 do
- while sec >0 do
- --getClick()
- if not timerPaused then
- sec = sec - 1
- else
- break
- end
- sendTime()
- getClick()
- end
- --getClick()
- if not timerPaused then
- if min > 0 then
- min = min-1
- sec = 59
- end
- else
- break
- end
- sendTime()
- getClick()
- end
- end
- function getClick()
- local timerCode = 0
- timerCode = os.startTimer(1)
- local event,side,x,y
- repeat
- event,side,x,y = os.pullEvent()
- until side == timerCode or event == "monitor_touch"
- if event == "monitor_touch" then
- button.checkxy(x,y)
- end
- end
- mainMenu()
- --findClocks()
- resetTimer()
- while true do
- getClick()
- end
- --runTimer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement