0

这是我的代码。我在玩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
4

1 回答 1

7

brown从代码中,我猜black是布尔类型,要么是true要么false。但是您将它们与以下内容进行比较:

t = true
f = nil 

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

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

if brown == t and black == f then

你可以用这个来测试它们:

if brown and not black then
于 2013-08-03T01:26:08.213 回答