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

How to make block repeat

Started by Nikolai, 30 November 2012 - 06:53 PM
Nikolai #1
Posted 30 November 2012 - 07:53 PM
How can I make lines 4 through 13 repeat until they enter the correct password?


os.pullEvent = os.pullEventRaw
print ("Door Status: Lock engaged")
print ("Enter Password")
write("Password:")
UserInput = io.read()
if UserInput == "Alpha" then
print ("Door lock disengaged")
rs.setOutput ("right", true )
sleep(5)
rs.setOutput ("right" , false )
os.shutdown()
else
print ("Password incorrect, try again")
Doyle3694 #2
Posted 30 November 2012 - 08:08 PM

os.pullEvent = os.pullEventRaw
while true do
   term.clear()
   term.setCursorPos(1,1)
   print ("Door Status: Lock engaged")
   print ("Enter Password")
   write("Password:")
   UserInput = io.read()
   if UserInput == "Alpha" then
	  print ("Door lock disengaged")
	  rs.setOutput ("right", true )
	  sleep(5)
	  rs.setOutput ("right" , false )
   else
	  print ("Password incorrect, try again")
	  sleep(1.5)
   end
end

You had missed an end. I added it, then I added a clear at the top. and then a "while true" loop. a while true loop will basically go forever. Also, I removed your os.shutdown() since its not needed in a while true loop ;)/>

Not tested but should work, otherwise, hand me the error and I'll fix it :)/>
Nikolai #3
Posted 01 December 2012 - 03:38 AM
Thanks