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

help with computer controlled door

Started by pancho507, 30 March 2016 - 11:26 AM
pancho507 #1
Posted 30 March 2016 - 01:26 PM

hi, i need help making my computer controlled door.

the source code is the following:

while true do

term.clear()

term.setCursorPos(1,1)

write("Password: ")

local input = read("*")

if input == asdf then

term.clear()

term.setCursorPos(1,1)

print("Password correct!")

rs.setOutput(back,true)

sleep(15)

rs.setOutput(back,false)

else
print("Password incorrect! :(/> yow will be able to enter the password after 10 seconds")
sleep(10)

end

end


note: adsf is yust for testing, it's not my real password

anyone who knows lua programming, can you help?!?!?????????????

if i input asdf, it says it's incorrect. and when i input anything else, it says it's incorrect, anyway. so it's kinda working except for this bug which renders it useless….



the code is a modified version of the original: http://computercraft.info/wiki/Making_a_Password_Protected_Door
Dog #2
Posted 30 March 2016 - 04:28 PM
You are currently comparing input to a variable named asdf. If you want to compare it to a string, you need to surround your string in quotes, like so…

if input == "asdf" then
ReBraLaCC #3
Posted 30 March 2016 - 05:18 PM
Maybe to make it look a little bit more 'alive' you can put something in for the waiting time like

for a = 1,10 do
write("You have to wait "..a.." more second(s)")
sleep(1)
end

and ofcourse use term.setCursorPos() to have a little bit less spam :D/>
Edited on 30 March 2016 - 03:18 PM