Lua“if-then”语句出错('end'预期(在第28行关闭'if'))
我有个错误,上面写着 老实说,我不知道我在做什么,因为我对Lua和编码都是新手。我认为这与没有终点有关Lua“if-then”语句出错('end'预期(在第28行关闭'if')),lua,computercraft,Lua,Computercraft,我有个错误,上面写着 老实说,我不知道我在做什么,因为我对Lua和编码都是新手。我认为这与没有终点有关 term.clear() term.setCursorPos(17, 4) print("Welcome") sleep(2) term.setCursorPos(8, 5) print("What lights would you like to control?") input = read() if input == "Hall" then term.clear() term.s
term.clear()
term.setCursorPos(17, 4)
print("Welcome")
sleep(2)
term.setCursorPos(8, 5)
print("What lights would you like to control?")
input = read()
if input == "Hall" then
term.clear()
term.setCursorPos(17,4)
print("On or Off?")
input = read()
if input == "on" then
redstone.setOutput("back", true)
print("Hall Lighting Turned On")
sleep(5)
shell.run("Lighting")
else
redstone.setOutput("back", false)
print("Hall Lighing Turned Off")
sleep(5)
shell.run("Lighting")
if input == "Bedroom" then
term.clear()
term.setCursorPos(17,4)
print("On or Off")
input = read()
if input == "on" then
redstone.setOutput("left", true)
print("Bedroom Lighting Turned On")
sleep(5)
shell.run("Lighting")
else
redstone.setOutput("left", false)
print("Bedroom Lighing Turned Off")
sleep(5)
shell.run("Lighting")
if input == "Labs" then
term.clear()
term.setCursorPos(17,4)
print("On or Off?")
input = read()
if input == "on" then
redstone.setOutput("right", true)
print("Lab Lighting Turned On")
sleep(5)
shell.run("Lighting")
else
redstone.setOutput("right", false)
print("Lab Lighing Turned Off")
sleep(5)
shell.run("Lighting")
end
else
print("Error")
sleep(3)
shell.run("Lighting")
end
看起来您在几个地方缺少结束词 结构应如下所示:
if ... then
some code
else
some optional code
end
此外,尝试更好地缩进代码。你会很清楚你应该把结尾词放在哪里
你想要的可能是:
term.clear()
...
input = read()
if input == "Hall" then
...
if input == "on" then
...
else
redstone.setOutput("back", false)
shell.run("Lighting")
end -- missing end!
end -- missing end!
if input == "Bedroom" then
...
if input == "on" then
...
else
redstone.setOutput("left", false)
...
shell.run("Lighting")
end -- missing end!
end -- missing end!
...
看起来您在几个地方缺少结束词 结构应如下所示:
if ... then
some code
else
some optional code
end
此外,尝试更好地缩进代码。你会很清楚你应该把结尾词放在哪里
你想要的可能是:
term.clear()
...
input = read()
if input == "Hall" then
...
if input == "on" then
...
else
redstone.setOutput("back", false)
shell.run("Lighting")
end -- missing end!
end -- missing end!
if input == "Bedroom" then
...
if input == "on" then
...
else
redstone.setOutput("left", false)
...
shell.run("Lighting")
end -- missing end!
end -- missing end!
...
您的if语句缺少很多end语句。使用缩进将极大地帮助您。您的if语句缺少很多end语句。使用缩进将极大地帮助您。