我在 ComputerCraft 中创建了一个“虚假”操作系统,它允许我从头开始构建我的系统用户可以做和不能做的事情。
然而,我似乎无法做的一件事是让这个操作系统在解析不存在的“程序”时给出有效的回归。
例如,我创建了程序“帮助、管理、数据库”我想要的是每当我输入这 3 个程序以外的内容时,就会出现诸如“程序不存在”之类的错误。
这个 LUA 操作系统的构建是为了让命令行界面看起来尽可能干净,而不是效率。这个操作系统是在 3 天的时间里构建的,所以失去我的位置很常见,因此有些事情并不完全平行。
这是我的脚本操作系统,它在启动 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