I am trying to make the computer check how much power Energy cell has, but when i run this program it says: attemt to index ? (a nil value) Any suggestions?
local energyCell = peripheral.wrap("back")
local energyCellMax = energyCell.getMaxEnergyStored("top")
local productionTime = 250
local energyPerTick = 320
local energyCreated = productionTime * energyPerTick * 20
local energyThreshold = energyCellMax - energyCreated
local dropperSide = "top"
local function dropperPulse()
redstone.setOutput(dropperSide, true)
sleep(1)
redstone.setOutput(dropperSide, false)
sleep(productionTime)
end
while true do
term.clear()
term.setCursorPos(1,1)
print("Current Charge Level:")
print(" "..math.floor(100*energyCell.getEnergyStored("top")/energyCellMax).."%")
if (energyCell.getEnergyStored("top") < energyThreshold) then
print("Charging...")
dropperPulse()
end
sleep(5)
end