我在ComputerCraft中创建了一个“假”操作系统,允许我从底层构建我的系统用户能够和不能做的事情。
然而,我似乎不能做的一件事是,每当解析不存在的“程序”时,这个操作系统就会给出一个有效的回滚。
例如,我已经创建了程序“帮助,管理,数据库”--我想要的是,每当我输入这三个程序之外的其他内容时,就会出现“程序不存在”之类的错误。
这个LUA操作系统是为了使命令行界面看起来尽可能干净,而不是为了提高效率。这个操作系统是在3天内建造的,所以失去我的位置是很常见的,因为这一点,有些事情并不是完全平行的。
这是我的scriptOS,它在启动ComputerCraft计算机时立即运行。
--Testing Comments--
--Program Start--
term.clear() //This deletes the CraftOS 1.7 watermark//
term.setCursorPos(1,1)
print("KappaCraft Interface: 2018 Edition")
print("")
sleep(.75)
print("Welcome to the Information Center!")
sleep(.75)
print("")
print("This system is not yet finished") //You're telling me//
print("")
sleep(.75)
print("Contact the Author of this program, Eleventy49, for any further questions")
sleep(2.0)
--Capabilities--
print("")
print("Type 'Commands' to see what you can do.")
sleep(.75)
print("")
--Setting up for Programs--
varyable = "true"
while varyable == "true" do
local input = read()
--Programs--
if input == "Commands" then
term.clear
term.setCursorPos(1,1)
print("This is the list of programs available to you")
print("")
print("Admin Commands Database Help Building Code")
print("")
sleep(2)
end
--Admin--
if input == "Admin" then
term.clear
term.setCursorPos(1,1)
write("Enter Password: ")
local passinput = read("*")
if passinput == "Classified" then
error("Adminstrator Access Granted") //This error forces me back into CraftOS, so I can edit this Script//
sleep(2)
term.clear()
else
print("Must be Administrator to Access this Program")
sleep(2)
end
end
--Builder's Code--
if input == "Building Code" then
term.clear()
term.setCursorPos(1,1)
shell.run("Builder")
print("The Builder's Code has been printed on your right") //Builder is a program that formats the building rules of the village onto computer craft printer sheets and then prints them//
end
--Help--
in input == "Help" then
term.clear()
term.setCursorPos(1,1)
print("Help with what? (EX: Help Commands)")
end
--Help Admin--
if input == "Help Admin" then
term.clear
term.setCursorPos(1,1)
print("This program lets Admins change settings")
end
--Help Commands--
if input == "Help Commands" then
term.clear
term.setCursorPos(1,1)
print("This program displays all the programs installed on this computer")
end
--Help Help--
if input == "Help Help" then
term.clear
term.setCursorPos(1,1)
print("This program explains what other programs do")
--Help Database--
if input == "Help Database" then
term.clear
term.setCursorPos(1,1)
print("This program lists all the plots and their owners in the city")
end
--Help Building Code--
if input== "Help Building Code" then
term.clear
term.setCursorPos(1,1)
print("This program prints the Building Code using the printer")
end
--Help Shutdown--
if input == "Shutdown" then
term.clear
term.setCursorPos(1,1)
print("This program shuts down the computer")
end
--Database--
if input == "Database" then
term.clear
term.setCursorPos(1,1)
print("This program is not yet complete")
end
--Shutdown--
if input == "Shutdown" then
term.clear
term.setCursorPos(1,1)
print("As you wish")
sleep(1)
os.shutdown()
end
end
发布于 2018-06-28 04:01:00
不要使用所有的if
/elseif
/else
块,而是使用if
块。见这里。因此,您可以对所有已接受的命令使用if
和elseif
,然后使用打印错误消息的最终else
。
https://stackoverflow.com/questions/51074455
复制相似问题