Advertisement
Link712011

energy

Aug 8th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.60 KB | None | 0 0
  1. local computer = require('computer')
  2.  
  3. local ENERGY_CHARGING_CHECK_SLEEP = 10
  4. local ERROR_TOLERANCE = 1000
  5. local energy = {}
  6.  
  7. local function wait_charging(func)
  8.     while computer.energy() < computer.maxEnergy() - ERROR_TOLERANCE do
  9.         if func then
  10.             func()
  11.         end
  12.         os.sleep(ENERGY_CHARGING_CHECK_SLEEP)
  13.     end
  14. end
  15. energy.wait_charging = wait_charging
  16.  
  17. local function get_max_energy()
  18.     return computer.maxEnergy()
  19. end
  20. energy.get_max_energy = get_max_energy
  21.  
  22. local function get_level()
  23.     return computer.energy()
  24. end
  25. energy.get_level = get_level
  26.  
  27. return energy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement