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

Password Lock WITHOUT rebooting?

Started by BlockDriller, 18 July 2013 - 04:23 AM
BlockDriller #1
Posted 18 July 2013 - 06:23 AM
So I tried to make one but it doesn't seem to work, any help?


term.clear()
term.setCursorPos(1, 1)
print("Enter password")
pass = read("*")
if pass == "pass" then
print("Welcome")
sleep(2)
term.clear()
term.setCursorPos(1, 1)
else
print("Goodbye")
sleep(2)
shell.run(startup)
end

PS: This is an unfinished version, I want to fix the code before I setup the text shown perfectly.
chiloxsan #2
Posted 18 July 2013 - 06:27 AM
So I tried to make one but it doesn't seem to work, any help?


term.clear()
term.setCursorPos(1, 1)
print("Enter password")
pass = read("*")
if pass == "pass" then
print("Welcome")
sleep(2)
term.clear()
term.setCursorPos(1, 1)
else
print("Goodbye")
sleep(2)
shell.run(startup)
end

PS: This is an unfinished version, I want to fix the code before I setup the text shown perfectly.

In this situation, you would use a loop. Loops repeat a block of code until either the loop condition returns false or the loop is broken out of through other means.


while true do
  term.clear()
  term.setCursorPos(1, 1)
  print("Enter password")
  pass = read("*")
  if pass == "pass" then
    print("Welcome")
    sleep(2)
    term.clear()
    term.setCursorPos(1, 1)
    break
  else
    print("Goodbye")
    sleep(2)
  end
end

When the password is correct, it calls the 'break' keyword. This keyword breaks out of the current loop.
BlockDriller #3
Posted 18 July 2013 - 06:33 AM
So I tried to make one but it doesn't seem to work, any help?


term.clear()
term.setCursorPos(1, 1)
print("Enter password")
pass = read("*")
if pass == "pass" then
print("Welcome")
sleep(2)
term.clear()
term.setCursorPos(1, 1)
else
print("Goodbye")
sleep(2)
shell.run(startup)
end

PS: This is an unfinished version, I want to fix the code before I setup the text shown perfectly.

In this situation, you would use a loop. Loops repeat a block of code until either the loop condition returns false or the loop is broken out of through other means.


while true do
  term.clear()
  term.setCursorPos(1, 1)
  print("Enter password")
  pass = read("*")
  if pass == "pass" then
	print("Welcome")
	sleep(2)
	term.clear()
	term.setCursorPos(1, 1)
	break
  else
	print("Goodbye")
	sleep(2)
  end
end

When the password is correct, it calls the 'break' keyword. This keyword breaks out of the current loop.

Worked perfectly, thanks.