Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Set your desired password
- local password = "your_password"
- -- Function to prompt for password input
- local function promptPassword()
- term.clear()
- term.setCursorPos(1,1)
- print("Enter password:")
- return read("*")
- end
- -- Function to monitor keyboard input
- local function monitorInput()
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.enter then
- return true -- Enter key pressed
- end
- end
- end
- -- Main function to run the program
- local function run()
- while true do
- local input = promptPassword()
- if input == password then
- redstone.setOutput("right", true) -- Emit signal to the left
- print("Access granted. Signal emitted to the left.")
- local timerID = os.startTimer(30) -- Start a timer for 30 seconds
- local inputThread = coroutine.create(monitorInput) -- Start monitoring keyboard input
- while true do
- local event, param = os.pullEvent()
- if event == "timer" and param == timerID then
- redstone.setOutput("right", false) -- Stop emitting signal after 30 seconds
- print("Signal stopped.")
- break
- elseif event == "key" and param == keys.enter then
- redstone.setOutput("right", false) -- Stop emitting signal if enter key is pressed
- print("Signal stopped early.")
- break
- elseif event == "terminate" then
- print("Program termination is disabled.")
- elseif event == "coroutine" and param == inputThread then
- print("Invalid thread state. Restarting...")
- break
- end
- end
- else
- print("Incorrect password. Try again.")
- end
- end
- end
- -- Run the program
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement