Advertisement
xX-AAAAAAAAAA-Xx

ComputerCraft Combination Lock

Aug 17th, 2024 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. -- Combination Lock Script with Redstone Signal
  2.  
  3. local correctPasscode = "5432"
  4. local userPasscode = ""
  5.  
  6. -- Function to clear the screen
  7. local function clearScreen()
  8.     term.clear()
  9.     term.setCursorPos(1, 1)
  10. end
  11.  
  12. -- Function to prompt user for input
  13. local function prompt(message)
  14.     clearScreen()
  15.     print(message)
  16. end
  17.  
  18. -- Function to handle passcode input
  19. local function getInput()
  20.     prompt("Enter passcode:")
  21.     userPasscode = read()
  22. end
  23.  
  24. -- Function to send redstone signal
  25. local function sendRedstoneSignal(duration)
  26.     rs.setOutput("left", true)  -- Send a redstone signal
  27.     sleep(duration)             -- Wait for the specified duration
  28.     rs.setOutput("left", false) -- Turn off the redstone signal
  29. end
  30.  
  31. -- Main program
  32. while true do
  33.     getInput()
  34.    
  35.     if userPasscode == correctPasscode then
  36.         prompt("Access Granted!")
  37.         sendRedstoneSignal(3)
  38.         sleep(2)
  39.     else
  40.         prompt("Incorrect passcode! Try again.")
  41.         sleep(2)  -- Wait for 2 seconds before clearing the screen
  42.     end
  43. end
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement