Guest User

timer

a guest
Jul 9th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 KB | None | 0 0
  1. local xs = 7
  2. local xm = 4
  3. local xh = 1
  4. local y = 1
  5. local monitor = peripheral.wrap("left")
  6. local m = 33
  7. local h = 5
  8. local c = 20
  9. local logic = 1
  10.  
  11. if not fs.exists("status") then
  12.     local file = io.open("status", "w")
  13.     file:write()
  14.     file:close()
  15. end
  16.  
  17. function write(path, text)
  18.     local file = assert(io.open(path, "w"))
  19.     file:write(text)
  20.     file:close()
  21. end
  22.  
  23. function writeFromTable(path, t)
  24.     local text = ""
  25.     for  _, line in pairs(t) do
  26.         text = text..line.."/n"
  27.     end
  28.     write(path, text)
  29. end
  30.  
  31. function getTable(path)
  32.     if fs.exists(path) then
  33.         local file = io.open(path, "r")
  34.         local lines = {}
  35.         local u = 1
  36.         local line = file:read("*1")
  37.         while line ~= nil do
  38.             lines[i] = line
  39.             line = file:read("*1")
  40.             u = u + 1
  41.         end
  42.         file:close()
  43.         return lines
  44.     end
  45.     return {}
  46. end
  47.  
  48. function w(path, n, text)
  49.     local lines = getTable(path)
  50.     lines[n] = text
  51.     writeFromTable(path, lines)
  52. end
  53.  
  54. local config = getTable("status")                      
  55. h = tonumber(string.sub(config[1], 1))
  56. m = tonumber(string.sub(config[2], 1))
  57. c = tonumber(string.sub(config[3], 1))
  58.  
  59. while logic==1 do
  60.     rs.setOutput("top",true)
  61.     for i = 60,0,-1 do
  62.         c = c-1
  63.         monitor.clear()
  64.         monitor.setCursorPos(3,1)
  65.         monitor.write(":")
  66.         monitor.setCursorPos(6,1)
  67.         monitor.write(":")
  68.         monitor.setCursorPos(xs,y)
  69.         monitor.write(tostring(c))
  70.         monitor.setCursorPos(xm,y)
  71.         monitor.write(tostring(m))
  72.         monitor.setCursorPos(xh,y)
  73.         monitor.write(tostring(h))
  74.         sleep(1)
  75.         w("status", 1,h)
  76.         w("status", 2,m)
  77.         w("status", 3,c)
  78.         if c == 0 then
  79.            c = 60
  80.            m = m-1
  81.            monitor.clear()
  82.            monitor.setCursorPos(3,1)
  83.            monitor.write(":")
  84.            monitor.setCursorPos(xs,y)
  85.            monitor.write(tostring(0))
  86.            monitor.setCursorPos(xm,y)
  87.            monitor.write(tostring(m))
  88.            monitor.setCursorPos(xh,y)
  89.            monitor.write(tostring(h))
  90.         end
  91.         if m == 0 then
  92.            m = 60
  93.            h = h-1
  94.            monitor.clear()
  95.            monitor.setCursorPos(6,1)
  96.            monitor.write(":")
  97.            monitor.setCursorPos(xs,y)
  98.            monitor.write(tostring(0))
  99.            monitor.setCursorPos(xm,y)
  100.            monitor.write(tostring(m))
  101.            monitor.setCursorPos(xh,y)
  102.            monitor.write(tostring(h))
  103.         end
  104.         if h ==0 then
  105.             if m == 0 then
  106.                 if c == 0 then
  107.                     logic = 0
  108.                 end
  109.             end
  110.         end
  111.     end
  112. end
Advertisement
Add Comment
Please, Sign In to add comment