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

control door piston

Question

 

Hello
Is it possible in the same program to have two passwords to control a door?
I find this in the archive and I wanted the modified but without success.

Quote

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


Thanks for your answers

Share this post


Link to post
Share on other sites

14 answers to this question

Recommended Posts

  • 0
local component = require("component")
local term = require("term")
local text = require("text")
local r = component.redstone

---- config section
local password = {["1234"] = true, ["foobar"] = true}
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()
  if wrong then
    print("Password was wrong, try again")
  else
    print("Please enter the password")
  end
  wrong = false
  local input = text.trim(term.read({pwchar='*'}) or "")
  if passwords[input] 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

 

Share this post


Link to post
Share on other sites
  • 0

Thanks for your reply, sorry i meant two password, one to open and one to closed.

So that the door stays open and only closes with the second password
Sorry for this mistake.

 

Share this post


Link to post
Share on other sites
  • 0
After several research I find this video, is it possible to adapt it for open computer? here are the two programs used

Startup file:

 

-- IF YOU USE THIS FOR MY TUTORIAL SAVE THE FILE AS "startup" WITHOUT EXTENSION
 
pass = "lol" -- CHANGE 'lol' IN TO WHAT EVER YOU LIKE TO CHANGE THE PASSWORD
 
-- DON'T TOUCH THE CODE IF YOU DON'T UNDERSTAND IT!
-- IF YOU USE MY CODE AND RELEASE IT ATLREAST GIVE ME SOME CREDIT ^^
 
term.clear()
term.setCursorPos(11,3)
print "[Door Terminal]"
term.setCursorPos(6,4)
print "[Enter security password]"
 
write "\nPassword: "
input = read()
 if pass == input then
  print "Password Correct"
  sleep(1)
  term.clear()
  shell.run( "door" )
 
 else
  print "Password Incorrect"
  print "Shutting down the system"
  sleep(1)
 
  os.shutdown()
end

 

Door file:

-- IF YOU USE THIS FOR MY TUTORIAL SAVE THE FILE AS "door" WITHOUT EXTENSION
-- DON'T TOUCH THE CODE IF YOU DON'T UNDERSTAND IT!
-- IF YOU USE MY CODE AND RELEASE IT ATLREAST GIVE ME SOME CREDIT ^^
 
term.clear()
term.setCursorPos(5,1)
print "[Door Terminal]"
term.setCursorPos(2,2)
print "Please select an option"
term.setCursorPos(2,3)
print "[1] Open Door"
term.setCursorPos(2,4)
print "[2] Close Door"
term.setCursorPos(2,5)
print "[3] Lock system"
term.setCursorPos(2,6)
print "[4] Shutdown system"
term.setCursorPos(2,8)
write "Option: "
input = read()
 
if input == '1' then
        redstone.setOutput("back", true)
        term.clear()
        shell.run("door")
elseif input == '2' then
        redstone.setOutput("back", false)
        term.clear()
        shell.run("door")
elseif input == '3' then
        term.setCursorPos(2,11)
        print "Locking the system"
        sleep(1)
        shell.run("startup")
elseif input == '4' then
        term.setCursorPos(2,11)
        print "System shutdown detected"
        sleep(0.5)
        term.setCursorPos(2,12)
        print "[Closing/Locking door]"
        sleep(1)
        os.shutdown()
        end
        term.clear()
        shell.run("door")
 Thanks for your help :)
 

Share this post


Link to post
Share on other sites
  • 0

This should do what you want. I didn't test it so it may not work. Just reply with the error message if it doesn't work.

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

---- config section
local password = {
  pw_open = "openMe",
  pw_close = "closeMe"
}
local side = 5 --side of the door
-----

local open = false
local input_password

local function checkPassword(i_password)
  if (i_password == password.pw_open & open == false) then
    return true
  elseif (i_password == password.pw_close & open == true) then
    return true
  else
    return false
  end
end

term.clear()
while true do
  print("Please enter the password:")
  input_password = text.trim(term.read({pwchar = "*"}) or "")
  if (checkPassword(input_password)) then
    if (open == true) then
      -- Close the door if open.
      print("Closing the door.")
      r.setOutput(side, 15)
    else
      -- Open the door if closed.
      print("Opening the door.")
      r.setOutput(side, 0)
    end
  else
    print("Password was wrong, try again")
  end
end

Share this post


Link to post
Share on other sites
  • 0
Thanks.
actually I do not have the mistake anymore,
but the closing password does not work.
when i type it he show me that "the password was wrong try again"

 

the first is the password to open and the second is the password to close

 

error.png

Share this post


Link to post
Share on other sites
  • 0

The program as I wrote it starts with the door open (Redstone signal off)

There were also a few mistakes (forgetting to change the internal tracking of the door state when closing/opening the door), so here is a (mostly) fixed version.

Edit: Tested: works.

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

---- config section
local password = {
  pw_open = "openMe", --pasword for opening
  pw_close = "closeMe" --pasword for closing
}
local side = 5 --side of the door
-----

local open = true
local input_password

local function checkPassword(i_password)
  if (i_password == password.pw_open and open == false) then
    return true
  elseif (i_password == password.pw_close and open == true) then
    return true
  else
    return false
  end
end

term.clear()
while true do
  print("Please enter the password:")
  input_password = text.trim(term.read({pwchar = "*"}) or "")
  if (checkPassword(input_password)) then
    -- *) reverse if runnig throug redstone torch (inverted)
    if (open == true) then
      -- Close the door if open.
      print("Closing the door.")
      r.setOutput(side, 15) --set redstone signal high. *)
      open = false
    else
      -- Open the door if closed.
      print("Opening the door.")
      r.setOutput(side, 0) --set redstone signal low. *)
      open = true
    end
  else
    print("Password was wrong, try again")
  end
end

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

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