我收到了一个错误
Run Code Online (Sandbox Code Playgroud)bios:14: [string "Lighting"]:58: 'end' expected (to close 'if' at line 28)
老实说我不知道自己刚开始做Lua和编码时我在做什么.我认为它与没有end某个地方有关.
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
Run Code Online (Sandbox Code Playgroud)
看起来你end在几个地方都缺少单词.
结构应该像:
if ... then
some code
else
some optional code
end
Run Code Online (Sandbox Code Playgroud)
另外,尝试更好地缩进代码.你会明白你应该把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!
...
Run Code Online (Sandbox Code Playgroud)