Advertisement
sshikamaru

CC - Timer avec reset

May 17th, 2014
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. i=0
  2. m = peripheral.wrap("back")
  3. m.clear()
  4.  
  5. if fs.exists("compteur_reacteur2") then
  6.     h = fs.open("compteur_reacteur2", "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.         time = 0
  20.     end
  21.      
  22.     local day = math.floor(time/86400)
  23.     local hrs = math.floor((time-day*86400)/3600)
  24.     local mins = math.floor((time-(hrs+day*24)*3600)/60)
  25.     local sec = math.floor(time-day*86400-hrs*3600-mins*60)
  26.      
  27.     if i==300 then
  28.         redstone.setOutput("right",true)
  29.         h = fs.open("compteur_reacteur2", "w")
  30.         h.write(time)
  31.         h.close()
  32.         i=0
  33.            
  34.         else
  35.         redstone.setOutput("right",false)
  36.     end  
  37.        
  38.     shell.run("clear")
  39.     m.setTextScale(3)
  40.     m.write(string.format('% 3d:%02d:%02d:%02d',day,hrs,mins,sec))
  41.     sleep(2)
  42.        
  43. end
  44.  
  45. --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