Advertisement
Guest User

housecontrol

a guest
Oct 26th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. password = "468"
  2. maxTries = 3
  3. numFails = 0
  4.  
  5. os.pullEvent = os.pullEventRaw
  6.  
  7. function checkPassword()
  8.   term.clear()
  9.   term.setCursorPos(1,1)
  10.  
  11.   print("Enter the password")
  12.   input = read("*")
  13.  
  14.   if input == password then
  15.   numFails = 0
  16.     return true
  17.   else
  18.     numFails = numFails + 1
  19.     return false
  20.   end
  21. end
  22.  
  23. while true do
  24. term.clear()
  25. term.setCursorPos(1,1)
  26.  
  27. print("What do you want to do?")
  28. print("1=Open Door")
  29. print("2=Close Door")
  30. print("3=Turn on Lights")
  31. print("4=Turn off Lights")
  32.  
  33. input = io.read()
  34.  
  35. if input == "1" then
  36.     if checkPassword() == true then
  37.     rs.setOutput("bottom",true)
  38.     else
  39.       term.clear()
  40.       term.setCursorPos(1,1)
  41.       print("Invalid Password")
  42.       if numFails < maxTries then
  43.         sleep(2)
  44.       else
  45.         print("Too many fails. Please wait")
  46.         sleep(30)
  47.       end
  48.     end
  49.   elseif input == "2" then
  50.     rs.setOutput("bottom",false)
  51.   elseif input == "3" then
  52.     rs.setOutput("back",false)
  53.   elseif input == "4" then
  54.     rs.setOutput("back",true)
  55.   elseif input == "bd" then
  56.   break
  57.   else
  58.     print("Invalid")
  59.     sleep(2)
  60. end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement