Guest User

Computercraft Countdown Timer

a guest
Jun 24th, 2013
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. -- Program named "startup"
  2.  
  3. local
  4. mon = peripheral.wrap("top")
  5. minute = ""
  6. second = ""
  7.  
  8. term.clear()
  9. term.setCursorPos(1, 1)
  10.  
  11. print("-~- How much time? -~-")
  12. print(" ")
  13.  
  14. term.write("Minutes: ")
  15. minute = read()
  16.  
  17. term.write("Seconds: ")
  18. second = read()
  19.  
  20. if second >= 60 then -- Error here. "test:20: attempt to compare string with number expected, got string"
  21.     print("Too many seconds. Please choose a number under 60.")
  22.     sleep(3)
  23.     os.reboot()
  24. end
  25.  
  26. term.clear()
  27. term.setCursorPos(1, 1)
  28.  
  29. while redstone.getInput("back")==false do
  30.     term.redirect(peripheral.wrap("top"))
  31.     mon.setTextScale(2)
  32.     term.clear()
  33.     term.setCursorPos(1, 1)
  34.     print(minute..":"..second)
  35.     sleep(.5)
  36.     print(minute.." "..second) -- Adds blinking effect to ":"
  37. end
  38.  
  39. if redstone.getInput("back") then
  40.     term.redirect(peripheral.wrap("top"))
  41.    
  42.     if second < 0 then
  43.         minute = minute-1
  44.     end
  45.    
  46.     if second < 0 then
  47.         second = 59
  48.     end
  49.    
  50.     if minute==0 and second==0 then
  51.         os.reboot()
  52.     end
  53.    
  54.     for i = 1, 60 do
  55.         term.redirect(peripheral.wrap("top"))
  56.         mon.setTextScale(2)
  57.         term.clear()
  58.         term.setCursorPos(1, 1)
  59.         print(minute..":"..second)
  60.         sleep(1)
  61.        
  62.         second = second-1
  63.     end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment