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

Please help password code not working!

Started by elliotjarnit, 12 October 2016 - 04:11 PM
elliotjarnit #1
Posted 12 October 2016 - 06:11 PM
Hi! I made a code for a password protected computer. The password part works but when i type it in the screen just goes blank.
Here is the code:
os.pullEvent = os.pullEventRaw
while true do
term.clear()
term.setCursorPos(1, 1)
print("CreeperCity Computer Security")
write("Password: ")
if read("*") == "2007" then
print("Access Granted")
sleep(2)
term.clear()
term.setCursorPos(1, 1)
break
else
print ("Incorrect Password")
sleep(1)
end
end
os.pullEvent = oldPull
hbomb79 #2
Posted 12 October 2016 - 08:39 PM
Firstly, you should get into the habit of using CODE tags when inserting code, makes it easier to read.


os.pullEvent = os.pullEventRaw
while true do
    term.clear()
    term.setCursorPos(1, 1)
    print("CreeperCity Computer Security")
    write("Password: ")
    if read("*") == "2007" then
        print("Access Granted")
        sleep(2)
        term.clear()
        term.setCursorPos(1, 1)
        break
    else
        print ("Incorrect Password")
        sleep(1)
    end
end
os.pullEvent = oldPull

Where are you defining oldPull? It should be `local oldPull = os.pullEvent` on the first line, before you override it.

My guess is you are setting pullEvent to nil, and then ComputerCraft is completely crashing when the main shell tries to yield.
Edited on 12 October 2016 - 06:40 PM
Larry84 #3
Posted 12 October 2016 - 09:44 PM
-snip-

My guess is you are setting pullEvent to nil, and then ComputerCraft is completely crashing when the main shell tries to yield.

I think you're right. Just add at the top of the code
 oldPull=os.pullEvent 
elliotjarnit #4
Posted 17 October 2016 - 12:20 AM
Firstly, you should get into the habit of using CODE tags when inserting code, makes it easier to read.


os.pullEvent = os.pullEventRaw
while true do
	term.clear()
	term.setCursorPos(1, 1)
	print("CreeperCity Computer Security")
	write("Password: ")
	if read("*") == "2007" then
		print("Access Granted")
		sleep(2)
		term.clear()
		term.setCursorPos(1, 1)
		break
	else
		print ("Incorrect Password")
		sleep(1)
	end
end
os.pullEvent = oldPull

Where are you defining oldPull? It should be `local oldPull = os.pullEvent` on the first line, before you override it.

My guess is you are setting pullEvent to nil, and then ComputerCraft is completely crashing when the main shell tries to yield.
It works now thanks!