-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword
More file actions
49 lines (40 loc) · 1.52 KB
/
password
File metadata and controls
49 lines (40 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- Password-protected door control program for ComputerCraft
local correctPassword = "defcon1" -- Set the password to "defcon1"
local side = "right" -- Side where the redstone signal is sent
-- Function to display ACCESS GRANTED message
local function displayAccessGranted()
print("====================================")
print(" ACCESS GRANTED ")
print("====================================")
end
-- Main program loop
while true do
-- Prompt the user for a password
print("Enter password:")
local inputPassword = read("*") -- The "*" hides the password input
-- Check if the inputted password is correct
if inputPassword == correctPassword then
displayAccessGranted()
-- Send redstone signal for 1 second to "open" the door
print("Opening the door...")
redstone.setOutput(side, true)
sleep(1)
redstone.setOutput(side, false)
-- Countdown for 6 seconds before closing the door
for i = 6, 1, -1 do
print("Door closes in " .. i .. " seconds...")
sleep(1)
end
-- Send another redstone signal for 1 second to "close" the door
print("Closing the door...")
redstone.setOutput(side, true)
sleep(1)
redstone.setOutput(side, false)
else
print("Access denied! Incorrect password.")
end
-- Wait for 2 seconds before prompting for password again
sleep(2)
term.clear()
term.setCursorPos(1,1) -- Reset cursor to the top of the screen
end