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
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

 

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 :)
 
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
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

 

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.