This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
graywolf69's profile picture

Help With Passwords

Started by graywolf69, 25 July 2014 - 10:43 PM
graywolf69 #1
Posted 26 July 2014 - 12:43 AM
Im having a problem with my program to launch a missile. Basically I wrote it to ask a password, once its entered ask if you are sure you want to launch, options Y/N, (basically another password, the password being Y or N). Then it simply outputs a redstone signal, and turns it off. But when I enter the first password, it says password incorrect every time. probably will be the same with the Y/N question as well. Please help, heres the program code:

local password = “test”
while true do
term.clear()
term.setCursorPos(1, 1)
print("Enter the Access Password:")
imput = read("*")
if input == "password" then
term.clear()
term.setCursorPos(1, 1)
print("Password Correct. Are you sure you want to Launch Missile A? Y/N")
imput = read("*")
if imput == "Y" then
print("Launching Missile…")
redstone.setOutput("left", true)
sleep(5)
redstone.setOutput("left", false)
print("Missile Launched Successfully")
elseif imput == "N" then
print("N selected, Rebooting…")
reboot()
else
print("Invalid Resonse: Valid response is Y/N")
end
else
print("Incorrect Password!")
sleep(2)
end
end
Lyqyd #2
Posted 26 July 2014 - 12:51 AM
You should decide whether to use "imput" or "input" as your variable name when you read and compare. You could use two different ones for the two different prompts, of course. The correct spelling of the English word is "input", by the way. You seem to have all but one of them spelled incorrectly.
graywolf69 #3
Posted 26 July 2014 - 01:02 AM
lol, thats the result of typing fast and not concentrating *derp* thank you it works
flaghacker #4
Posted 26 July 2014 - 08:00 AM

if input == "password" then

Are you sure it works? What are those quotes doing there? You have declared a variable password, don't you want to use that?

And you use reboot(), shouldn't that be os.reboot()?
Edited on 26 July 2014 - 06:01 AM