我在ComputerCraft中创建了一个“假”操作系统,该操作系统使我能够从头开始构建系统用户可以做什么和不能做什么。
但是,我似乎无法做的一件事情就是让该OS在解析不存在的“程序”时提供有效的回退。
例如,我创建了“帮助,管理,数据库”程序 我想要的是,只要我输入除这三个程序以外的其他内容,就会出现诸如“程序不存在”之类的错误。
此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
答案 0 :(得分:0)
使用if
/ if
/ elseif
块,而不是全部使用else
块。参见here。因此,您可以对所有接受的命令使用if
和elseif
,然后使用最终的else
打印错误消息。