Minecraft の mod である 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)
コードボックスが機能しませんでした
とにかく、これを修正する方法を知っている人はいますか?