我试图让计算机检查能量电池有多少电量,但是当我运行这个程序时它说:尝试索引?(零值)有什么建议吗?
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