Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
minecraft64

Passworded Boor

Question

Description:


  I need a program that allows me to have a password protect door say, to the right of the computer


Function:


Just to have a password to open the door


 


Deadline:


  I don't mind.


 


Additional Information:


  None but simply ask me if you have other questions


 


Thank you in advance!

Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

try this, but i did not test it.

local component=require("component")
local r=component.redstone
local gpu=component.gpu
local term=require("term")

---- config section
local password="1234"
local delay=5 --time the door stays open
local side=5 --side of the door, test this
-----

local wrong=false

while true do
  term.clear()
  gpu.set(1,1,"Please enter the password")
  if wrong then
    gpu.set(1,1,"Password was wrong, try again")
    wrong=false
  end
  term.setCursor(1,2)
  local input=io.read()
  if input==password then
     r.setOutput(side,15) -- check if this is the correct function
     os.sleep(delay)
     r.setOutput(side,0) -- same here
  else
     wrong=true
  end
end

Link to post
Share on other sites
  • 0

You can use this code for passwordless door:

local user = { "user1", "user2", "user3" }
 
local red = component.proxy(component.list("redstone")())
local scr = {}
local gpu = {}
 
for a in component.list("screen") do table.insert(scr, a) end
for a in component.list("gpu") do table.insert(gpu, component.proxy(a)) end
for i = 1, #gpu do gpu[i].bind(scr[i]) end
 
function showState(s)
  for i, g in ipairs(gpu) do
    g.setResolution(40, 20)
    g.fill(1, 1, 40, 20, " ")
    if s then
      g.setForeground(0x00FF00)
      g.set(16, 10, "Access denied")
    else
      g.setForeground(0xFF0000)
      g.set(16, 10, "Access granted")
    end
  end
end
 
function sleep(x)
  local tgt = computer.uptime() + x
  while computer.uptime() < tgt do
    computer.pullSignal(tgt - computer.uptime())
  end
end
 
while true do
  showState(false)
  local type, _, x, y, btn, nick = computer.pullSignal(5)
  if type == "touch" then
    nick = nick:lower()
    for i, v in ipairs(user) do
      if v == nick then
        showState(true)
        red.setOutput(1, 255)
        sleep(2)
        red.setOutput(1, 0)
      end
    end
  end
end 

Modify user list on top of code, flash it to EEPROM, connect some screens, install same amount of GPUs and one redstone block. Program will trigger pulse on top side of it.

Link to post
Share on other sites
  • 0

well that's also a way. but isn't your sleep function the wrong way to let the computer "sleep" and is calling os.sleep(x) not the better way?

You'd be surprised how OpenOS does it. Though the OpenOS version is slightly better, as it uses event.pull, which means that signals happening during sleep are properly passed on to any listener functions instead of being swallowed by the sleep loop.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.