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

Pretty Decent Code (Good Password Protection)

Started by DarkCoder, 04 November 2012 - 08:34 AM
DarkCoder #1
Posted 04 November 2012 - 09:34 AM
Right, so yer! I made this code as me and my brother are doing a playthrough only using turtles computers etc (No mining or any crap like that :D/>/>). We're fighting to win against one another and I needed to protect my house so I came up with this:


term.clear() term.setCursorPos(1,1)
y = 3
local password = "dark"
while true do
print("Attempts left:"..y)   -- Add In Variable!
write("Enter Password Here:")
local passwordRead = read("*")
if passwordRead == password then
rs.setOutput("right",true)
sleep(2)
rs.setOutput("right",false)
os.shutdown()
else
print("Try Again")
term.clear()
y = y-1
if y == 0 then
print("Chances Up Locking Computer!")
sleep(15)
os.shutdown()
end
end
end


Hope This helped. Basically what it does is uses variables to count down how many attempts are left before the computer is locked or what have you.

:)/>/>


if hungerLevel() > 1 then
  playMoreCC()
end
sjele #2
Posted 04 November 2012 - 09:52 AM

os.pullEvent = os.pullEventRaw

If not os.pullEvent = os.pullEventRaw then
ctrl+t have a nice day()
end

I hope you took, that. You need that to prevent termination.
DarkCoder #3
Posted 04 November 2012 - 09:56 AM
yer i know about that but i havent implemented it atm
thanks though
DarkCoder #4
Posted 04 November 2012 - 10:00 AM
heres one i just came up with:


function lock()
  term.clear()
  term.setCursorPos(1,1)
os.pullEvent = os.pullEventRaw
pass = io.read()
if pass == "dark" then
rs.setOutput("right",true)
sleep(2)
rs.setOutput("right",false)
lock()
else
lock()
end
end
lock()


[

if hungerLevel() > 1 then
  playMoreCC()
end