这是我的代码。我正在玩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
答案 0 :(得分:7)
从代码中,我猜测brown
和black
是布尔类型,可以是true
或false
。但是你要将它们与:
t = true
f = nil
这是不正确的,因为虽然false
和nil
都是假值,但它们不相同,即false
不等于nil
。所以将其更改为f = false
。
但是,这有点多余,if语句中不需要t
和f
。当你使用:
if brown == t and black == f then
你可以用它来测试它们:
if brown and not black then