如果陈述不适用于Lua

时间:2013-08-03 01:13:22

标签: lua

这是我的代码。我正在玩tekkit并希望控制水流量。棕色线上有红石的力量但不是黑色,但它仍然是ERROR!任何人都知道我的问题是什么?

在Lua代码中:

shell.run("clear")
brown = rs.testBundledInput("back", colors.brown)
black = rs.testBundledInput("back", colors.black)
t = true
f = nil

if brown == t and black == f then
  redstone.setBundledOutput("back", restone.getBundledOutput("back") -colors.brown)
  print("All water is flowing.")
  sleep(3)
  shell.run("2")
elseif brown == f and black == t then
  redstone.setBundledOutput("back", restone.getBundledOutput("back") -colors.black)
  print("All water is flowing.")
  sleep(3)
  shell.run("2")
elseif brown == t and black == t then
  redstone.setBundledOutput("back", restone.getBundledOutput("back") -colors.brown)
  redstone.setBundledOutput("back", restone.getBundledOutput("back") -colors.black)
  print("All water is flowing.")
  sleep(3)
  shell.run("2")
elseif brown == f and black == f then
  print("All water is flowing.")
  sleep(3)
  shell.run("2")
else
  print("ERROR!")
end

1 个答案:

答案 0 :(得分:7)

从代码中,我猜测brownblack是布尔类型,可以是truefalse。但是你要将它们与:

进行比较
t = true
f = nil 

这是不正确的,因为虽然falsenil都是假值,但它们不相同,即false不等于nil。所以将其更改为f = false

但是,这有点多余,if语句中不需要tf。当你使用:

if brown == t and black == f then

你可以用它来测试它们:

if brown and not black then