Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. mon = peripheral.wrap("top")
  2. cycle = 5
  3. energy = {}
  4. translation = {}
  5.  
  6. function loop()
  7.  
  8.     mon.clear()
  9.     mon.setCursorPos(0, 0)
  10.     mon.write("Energiezustand: ")
  11.  
  12.     for per in peripheral.getNames() do
  13.    
  14.         local energystored = per.getEnergyStored()
  15.         if tableHasKey(energy, per) then
  16.             if energystored > energy[per] then
  17.                 mon.write("+ ")
  18.             else
  19.                 mon.write("- ")
  20.             end
  21.         else
  22.             mon.write("X ")
  23.         end
  24.    
  25.         mon.write(Math.floor(energystored)
  26.         mon.write(translate(per)
  27.    
  28.    
  29.         energy[per] = energystored
  30.         -- Return to beginn
  31.         local x, y = mon.getCursorPos()
  32.         mon.setCursorPos(x + 1, 0)
  33.     end
  34.  
  35. end
  36.  
  37.  
  38. function translate(str)
  39.     if tableHasKey(str) then
  40.         return translation[str]
  41.     else
  42.         return str
  43.     end
  44. end
  45.  
  46. function tableHasKey(table,key)
  47.     return table[key] ~= nil
  48. end
  49.  
  50. function run()
  51. while true do
  52.     loop()
  53.     os.sleep(cycle)
  54. end
  55.  
  56.  
  57. end
  58. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement