【发布时间】:2015-04-11 02:13:05
【问题描述】:
我正在学习计算机技术(我的世界)编程,但在读取某些存储单元时遇到了一些麻烦。
我正在处理的函数将遍历所有单元格并将存储容量添加到 for 循环中的变量中。
这是我目前得到的
local cell1 = peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_2")
local cell2 = peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_3")
local cell3 = peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_4")
local cell4 = peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_5")
local cell5 = peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_6")
local cell6 = peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_7")
cells = {"cell1", "cell2", "cell3", "cell4", "cell5", "cell6"}
local totStorage
function getTotStorage(table)
for key = 1,6 do
x = table[key]
totStorage = totStorage + x.getMaxEnergyStored()
end
print(totStorage)
end
我在这一行得到一个错误
totStorage = totStorage + x.getMaxEnergyStored()
说“尝试调用 nil”。 有什么建议么?
【问题讨论】:
标签: function lua computercraft