Posted 20 November 2012 - 03:13 PM
Hello, since this is my first post on these forums, I'll begin by saying that I apologize if the thread title is incorrect, since I don't know if normal CC coding would be considered 'lua' or not, hence my single [Question] tag. My program is meant to send the user to a menu, where they can pick either 'Nuclear Management' or 'Forcefield Management', and it works nicely; however, I was wondering if I could add some password protection before people can access the computer. I have tried adding this line of code before my main code, but it didn't work; a password prompt pops up, but even if I enter the password correctly, nothing happens.
then my code
I apologize if this code is unkempt and just a pain to look at for some more experienced coders here, but I am an absolute beginner to any type of coding. I have used some reference code to fix up my code and produce what you see up there.
It would be extremely appreciated if someone could correct me or send me in the right direction.
Thanks a lot.
while true do
term.clear()
term.setCursorPos(1,1)
print("Enter access code:")
local input = read("*")
if input == "codeone" then
then my code
while x ~= "exit" do
print("--------------------")
print("TownyHub main menu:")
print("Enter 'nuclear' for nuclear management.")
print("Enter 'forcefield' for forcefield management.")
print("Enter 'exit' to go back to the previous menu.")
write("Choose an option now, please.")
print("--------------------")
x = io.read()
if x == "nuclear" then
while y ~= "exit" do
print("-------------------")
print("Nuclear menu:")
print("To turn the reactor on, type on. To turn the reactor off, type off.")
print("To return to the main menu, type exit.")
write("")
print("-------------------")
y = io.read()
if y == "off" then
rs.setOutput("left", true)
print("----------------")
print("You have chosen to turn off the nuclear reactor.")
elseif y == "on" then
rs.setOutput("left", false)
print("----------------")
print("You have chosen to turn on the nuclear reactor.")
end
end
end
if x == "forcefield" then
while u ~= "exit" do
print("-----------------")
print("Forcefield menu:")
print("-")
print("To turn on forcefield, type 'on'. To turn it off, type 'off'")
print("To exit to the main menu, type 'exit'")
write("")
print("-----------------")
u = io.read()
if u == "on" then
rs.setOutput("right",true)
print("------------------")
print("Forcefields: Operational")
elseif u == "off" then
rs.setOutput("right",false)
print("------------------")
print("Forcefields: Non-Operational")
end
end
end
end
end
end
I apologize if this code is unkempt and just a pain to look at for some more experienced coders here, but I am an absolute beginner to any type of coding. I have used some reference code to fix up my code and produce what you see up there.
It would be extremely appreciated if someone could correct me or send me in the right direction.
Thanks a lot.