Advertisement
sshikamaru

CC - timer sans reset

May 5th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. i=0
  2. m = peripheral.wrap("back")
  3. m.clear()
  4.  
  5. if fs.exists("compteur_reacteur") then
  6.     h = fs.open("compteur_reacteur", "r")
  7.     time = h.readAll()
  8.     h.close()
  9.     else
  10.     time = 0
  11. end
  12.  
  13. while true do
  14.  
  15.     if redstone.getInput("top",true) then
  16.         time = time + 1
  17.         i = i + 1
  18.     else
  19.     end
  20.      
  21.     local day = math.floor(time/86400)
  22.     local hrs = math.floor((time-day*86400)/3600)
  23.     local mins = math.floor((time-(hrs+day*24)*3600)/60)
  24.     local sec = math.floor(time-day*86400-hrs*3600-mins*60)
  25.      
  26.     if i==300 then
  27.         redstone.setOutput("left",true)
  28.         h = fs.open("compteur_reacteur", "w")
  29.         h.write(time)
  30.         h.close()
  31.         i=0
  32.            
  33.         else
  34.         redstone.setOutput("left",false)
  35.     end  
  36.        
  37.     shell.run("clear")
  38.     m.setTextScale(3)
  39.     m.write(string.format('% 3d:%02d:%02d:%02d',day,hrs,mins,sec))
  40.     sleep(1)
  41.        
  42. end
  43.  
  44. --crée par sshikamaru // Citez moi ainsi que le serveur Sphère-ville si vous utilisez ou modifiez ce code.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement