我正在使用 Minecraft 模组 Computercraft,我需要一些帮助。我试图找到一种类型的所有外围设备,从中获取能量,然后将它们加在一起。但是,我收到“尝试对 nill 执行算术”或其他错误。这是我的代码:
local periList = peripheral.getNames()
energy = 0
totalenergy = 0
for i = 1, #periList do
if peripheral.getType(periList[i]) == "cofh_thermalexpansion_energycell" then
local cell = peripheral.wrap(periList[i])
print(periList[i])
if cell.getEnergyStored("potato") ~= "nil" then
energy = cell.getEnergyStored("potato")
print(cell.getEnergyStored("potato"))
else
energy = 0
print(0)
end
totalenergy = totalenergy + energy
end
end
print(totalenergy)
抱歉,密码箱不起作用
无论如何,有人知道如何解决这个问题吗?