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

Loops and repeat until

Started by estrong1, 30 March 2013 - 07:54 AM
estrong1 #1
Posted 30 March 2013 - 08:54 AM
Hello again, I had an earlier post where I asked about loops and got a good response, but I am still unable to fully figure out what is wrong with my code.

The code is for a password door that gives 3 guesses before it gives a redstone output.


os.pullEvent = os.pullEventRaw
local password = "password123"
local guess = 0
  repeat
	term.clear()
	term.setCursorPos(1,1)
	write("Password: ")
	local input = read("*")
  if input == password then
	term.clear()
	term.setCursorPos(1,1)
	print("Correct!")
	rs.setOutput("right",true)
	sleep(5)
	rs.setOutput("right",false)
  else
	print("Try again...")
	guess = guess + 1
  until guess == 3
	print("Good bye!")
	rs.setOutput("back",true)
	sleep(5)
	rs.setOutput("back",false)
end

If you could help me out by showing me what to fix that would be great, thanks!
faubiguy #2
Posted 30 March 2013 - 09:02 AM
You need and end for the if/else block, after
guess = guess + 1
.
The end on the last line should be removed, because repeat until loops don't use an end statement.
estrong1 #3
Posted 30 March 2013 - 09:06 AM
You need and end for the if/else block, after
guess = guess + 1
.
The end on the last line should be removed, because repeat until loops don't use an end statement.

Thanks, it worked!