NielsUtrecht

base-energy

Sep 8th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. local confMainPort = 1000
  2. local confMyPort = 1003
  3. local confModemSide = "right"
  4.  
  5. local cellData = {}
  6.  
  7. if(not os.loadAPI("hydraApi")) then
  8.     error("Could not load hydraApi")
  9. end
  10.  
  11. local modem = peripheral.wrap(confModemSide)
  12. local cells = hydraApi.getAllEnergyCells()
  13.  
  14. if(modem == nil) then
  15.     print("No modem found")
  16. end
  17.  
  18. while true do
  19.  
  20.     local totalEnergy = 0
  21.     local totalMaxEnergy = 0
  22.    
  23.     for k,cell in pairs(cells) do
  24.         totalEnergy = totalEnergy + cell.getEnergyStored()
  25.         totalMaxEnergy = totalMaxEnergy + cell.getMaxEnergyStored()
  26.     end
  27.    
  28.     cellData["totalEnergy"] = totalEnergy
  29.     cellData["totalMaxEnergy"] = totalMaxEnergy
  30.     cellData["fraction"] = totalEnergy / totalMaxEnergy
  31.    
  32.     hydraApi.printTable(cellData)
  33.    
  34.     if(modem ~= nil) then
  35.         modem.transmit(confMainPort, confMyPort, cellData)
  36.     end
  37.  
  38.     os.sleep(2)
  39. end
Advertisement
Add Comment
Please, Sign In to add comment