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

Trying to make a locked computer

Started by ZegMaarWilly, 07 November 2015 - 07:54 PM
ZegMaarWilly #1
Posted 07 November 2015 - 08:54 PM
Hello everybody,

Ive been trying to make an locked computer and it hasnt quite worked out for me,
i'm new to this all and need some help on this, everytime i enter my code it says "Access Granted" but than puts me back on the login screen
My next step will be trying to make a locked communication system / floppy disks, so if you got any tips for those :)/>

Here is the code (I didn't know how to put it in any other way)


os.pullEvent = os.pullEventRaw
if true than do
term.clear()
term.setCursorPos(1, 1)
textutils.slowPrint("Enter Password:")
input = ("*")
if input == "Hello" then
term.clear()
term.setCursorpos(1, 1)
textutils.slowPrint("Welcome User!")
else
textutils.slowPrint("Incorrect Password!")
sleep(5)
end
end
end

Thanks for the help :D/>!
Creator #2
Posted 07 November 2015 - 10:42 PM
I believe you want to change the second line to "while true do". By the way, the keyword is then, not than. Also, after printing "Welcome user" add break on a new line. The code should look like this:

os.pullEvent = os.pullEventRaw
while true do
term.clear()
term.setCursorPos(1, 1)
textutils.slowPrint("Enter Password:")
input = ("*")
if input == "Hello" then
term.clear()
term.setCursorpos(1, 1)
textutils.slowPrint("Welcome User!")
break
else
textutils.slowPrint("Incorrect Password!")
sleep(5)
end
end
end
KingofGamesYami #3
Posted 07 November 2015 - 11:05 PM
By the way, "*" will never equal "Hello". You may want to use read( "*" )
Edited on 07 November 2015 - 10:06 PM
Hydrotronics #4
Posted 07 November 2015 - 11:26 PM

os.pullEvent = os.pullEventRaw
if true than do
term.clear()
term.setCursorPos(1, 1)
textutils.slowPrint("Enter Password:")
input = ("*")
if input == "Hello" then
term.clear()
term.setCursorpos(1, 1)
textutils.slowPrint("Welcome User!")
else
textutils.slowPrint("Incorrect Password!")
sleep(5)
end
end
end

I've noticed that if you get it wrong, it allows you into the computer anyway, so i was thinking maybe for the end result of getting it wrong you could do:

--Password Code
else
textutils.slowPrint("Incorrect Password")
sleep(1)
os.reboot()
end

I also changed the sleep time as waiting 5 seconds is just boring.

also, i have a strongish lock if you're willing to use:



os.pullEvent = os.pullEventRaw

term.clear()
term.setCursorPos(1,1)
print"Enter Password"
write""
input = read("*")
if input == "hello" then
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Welcome...")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print"CraftOS 1.7"
else
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Incorrect Password")
sleep(1)
os.reboot()
end

It is a simple yet effective password.
I didn't bother making it look pretty either, but you can do that yourself if you want :)/>
Also, This code means you dont need to have tons of ends at the end of the code, also, it doesn't use a while loop, which isn't very good i think.