我正在用一些自定义的mods制作一个保险库,我正在使用一台computercraft计算机来控制门,但我只能打开门而不能关闭门。这段代码正确吗?
term.setTextColor(colors.yellow)
print("Vault-Tec Door Computer")
term.setTextColor(colors.white)
print("What Command Would You Like To Do?")
term.setTextColor(colors.blue)
print("Vault.Open")
print("Vault.Close")
print("")
term.setTextColor(colors.white)
io.write("Vault-Tec:")
io.close()
if io.read()=="Vault.Open" then
term.setTextColor(colors.red)
print("VAULT DOOR OPENING, PLEASE STAND BACK")
term.setTextColor(colors.white)
redstone.setAnalogOutput("bottom", 0)
sleep(5)
end
if io.read()=="Vault.Close" then
term.setTextColor(colors.red)
print("SHUTTING VAULT DOOR, PLEASE STAND BACK")
term.setTextColor(colors.white)
redstone.setAnalogOutput("bottom", 15)
sleep(5)
end发布于 2018-10-14 16:52:16
您的第一个if语句调用io.read(),读取输入的内容并将其与Vault.Open进行比较。下一个if语句将读取键入的下一个内容,并将其与Vault.Close进行比较。
.....
local valutStatus = io.read()
if valutStatus == "Vault.Open" then
term.setTextColor(colors.red)
print("VAULT DOOR OPENING, PLEASE STAND BACK")
term.setTextColor(colors.white)
redstone.setAnalogOutput("bottom", 0)
sleep(5)
end
if valutStatus == "Vault.Close" then
term.setTextColor(colors.red)
print("SHUTTING VAULT DOOR, PLEASE STAND BACK")
term.setTextColor(colors.white)
redstone.setAnalogOutput("bottom", 15)
sleep(5)
endhttps://stackoverflow.com/questions/52799615
复制相似问题