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

Simple Password Door - Why doesn't this code work?

Started by Vivo13, 08 September 2014 - 07:30 AM
Vivo13 #1
Posted 08 September 2014 - 09:30 AM
Hi Guys!

I'm really new to ComputerCraft, and I mainly use it just for locking doors. Can someone tell me why this code isn't working? I've looked through it, and I just don't see any problems with it.

local oldPull = os.pullEvent;
os.pullEvent = os.pullEventRaw;
term.clear()
term.setCursorPos(1,1)
correctpass = "Home"
write("Key?")
pass = read("*")
if pass == (correctpass) then
write("Welcome Home")
redstone.setOutput("right", true )
sleep (3)
redstone.setOutput("right", false )
os.shutdown()
end
write("Wrong Key")
sleep (3)
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Locking Door")
sleep (3)
os.shutdown()
os.pullEvent = oldPull;

Thanks in advance!
KingofGamesYami #2
Posted 08 September 2014 - 02:04 PM
What part isn't working? It seems fine.
flaghacker #3
Posted 08 September 2014 - 03:39 PM
Try to remove the parentheses on line 8, I don't think they can be used like that.
Bomb Bloke #4
Posted 08 September 2014 - 04:13 PM
They can.
flaghacker #5
Posted 08 September 2014 - 04:36 PM
They can.
I'm earning every day :P/>
Bomb Bloke #6
Posted 08 September 2014 - 04:38 PM
Such is the nature of employment, I guess. :)/>
enforcer4100 #7
Posted 09 September 2014 - 11:19 AM
Shouldn't you have an else(if) part for writing line 15 onwards?
I think you currently 'override' the first part of your code, but I am not good at CC myself either.
Bomb Bloke #8
Posted 09 September 2014 - 12:47 PM
If the correct password is entered, then the system will shut down before reaching line 15 due to line 13.

Generally I'd use a "while" loop instead of turning the system off (in which case, yeah, you'd need to account for continued execution), though it does strike me that disabling the system entirely until another user has cause to play with it would lead to a lesser workload for the MineCraft server.