Lua - 将数据保存到for循环中的数组

时间:2014-03-23 02:50:47

标签: arrays lua computercraft

在我的lua程序中,我想检查两侧是否有红石输入(使用for循环检查)。 最后几行是打印出阵列的结果,作为调试工具。输出是名称后跟0(预期为true / false)。数据将在稍后的程序中使用。

谢谢。

http://www.pastebin.com/0innMjcP

function array()
  a = {}
  for i=1, 6 do
    a[i] = {}

    for j=1, 2 do
      a[i][j] = 0
    end
  end
  a[1][1]= "front"
  a[2][1]= "back"
  a[3][1]= "left"
  a[4][1]= "right"
  a[5][1]= "top"
  a[6][1]= "bottom"
end

array()

for i=1, 6 do
  input=redstone.getInput(a[i][1])
  if input=="true" then
    a[2][2]="true"

  elseif input=="false" then
    a[3][2]="false"
  end
end
for i=1, 6 do
  print(a[i][1])
  print(a[i][2])
end

1 个答案:

答案 0 :(得分:2)

manual of redstone.getInput(),它返回一个布尔值,而不是一个字符串,所以这一行

if input == "true" then

应该是

if input == true then

elseif部分相同。

相关问题