Ungarscool1

compteur

Aug 3rd, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.57 KB | None | 0 0
  1. p = {}
  2. rednet.open("right")
  3. local x = {peripheral.find("EnergyMeterRF")}
  4.  
  5. for k,v in  pairs(x) do
  6.     p[v.getLabel()] = v
  7. end
  8.  
  9. function loadDB()
  10.   local f = fs.open("db", "r")
  11.   db = textutils.unserialize(f.readAll())
  12.   f.close()
  13. end
  14.  
  15. function saveDB()
  16.   local f = fs.open("db", "w")
  17.   f.write(textutils.serialize(db))
  18.   f.close()
  19. end
  20.  
  21. while true do
  22.     e = {}
  23.     for k,v in pairs(p) do
  24.         if not v.isOutputAllowed() then
  25.             e[k] = -1
  26.             v.reset()
  27.         else       
  28.             e[k] = v.getCountAndReset()
  29.         end
  30.     end
  31.     rednet.send(171,textutils.serialize(e))
  32.     os.sleep(1)
  33. end
Add Comment
Please, Sign In to add comment