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

badcode9

Members
  • Content Count

    5
  • Joined

  • Last visited

Posts posted by badcode9

  1. Yes, options as you describe them, as well as input parameters such as numbers or strings that can be used by the program. eg. a farming program might accept the following: "farm 9 9"

     

    The provided digits might indicate the dimensions to farm within.

  2. To have any program run when the computer boots, you will need to call it from an autorun script.

    1. First, what I would suggest is to place your program in the "/usr/bin" directory, that way it can be called by name without specifying the directory path. This is optional but I find it useful.
    2. Next, create a new file in the root "/" directory, called "autorun.lua". In this script, use the following code, supposing your program name was "pass.lua". Then reboot it too test. 
    os.execute("pass.lua")

    As far as preventing program termination, I have found one post that describes a method involving creating your answer string from key strokes; however I have not implemented it yet myself. If you do let me know how it worked out for you.

     

    My program is below. I'd consider it 90% done with some potential enhancements. I'll release it in a more formal manor when I'm fully done, but you're welcome to use whatever you'd like.

     

    Cheers!

     

    --[[ 
      Password Lock Program for OpenComputers
    
    
      This program is designed to run indefinitely on a basic terminal to provide 
      password protection via redstone. It includes configurations for the door open
      duration, redstone output side, password, and an "admin" break password that will
      allow a user to gracefully terminate the program.
    
    
      By badcode9, 2016
    ]]
    
    local component = require("component")
    
    if not component.isAvailable("redstone") then
      io.stderr:write("This program requires either a Redstone Card Tier 1 or Redstone I/O block to run.\n")
      return
    end
    local rs = component.redstone
    
    local os = require("os")
    local term = require("term")
    local text = require("text")
    local sides = require("sides")
    
    
    
    
    --[[ Config ]]-----------------------------------------------------------------
    local pass = "password"
    local d = 5 -- Door open duration
    local s = sides.bottom -- Where to output redstone signal to open the door
    
    --[[ Door Control ]]-----------------------------------------------------------
    local function openDoor(duration)
      -- Open door for the duration provided, then close again.
      rs.setOutput(s, 0)
      os.sleep(duration)
      rs.setOutput(s, 255)
    end
    
    --[[ Main ]]-------------------------------------------------------------------
    
    -- Close door on init
    rs.setOutput(s, 255)
    
    while true do
     term.clear()
    
     -- Password Request
     print("Enter Password:")
     answer = text.trim(term.read(nil, false, nil, "*"))  -- Masking input characters; trim newline
     term.setCursor(1,2)
     term.clearLine()
    
     -- Password Check
     if answer == "admin" then -- admin pwd to break execution
      term.clear()
      print("Admin Override\n")
      return
     elseif answer == pass then
       print("ACCESS GRANTED")
       openDoor(d)
     else
       print("ACCESS DENIED")
       os.sleep(3)
     end
    end

     

  3. I am having a similar issue with accessing the robots internal inventory, but it doesn't appear that there is a dedicated function. I want to count the number of slots in the robots inventory, and anticipated that the function, getInventorySize(side: number): number or nil[, string] would work.

     

    However, when I use this function specifying "sides.back", I get an unsupported sides error (like Jalopy43 did).

     

    Does anybody know how I can accomplish this without the need for an additional block?

     

    Thanks!

  4. Hi The Duke of Crawley,

     

    I was actually working on something very similar as well this weekend. I opted to use the term.read() function, which allows you to mask the input. I don't think io.read() does this.. Would be cool if you could link the documentation for that function.

     

    Here's a snippet of my code. I'd be happy to share the whole program with you if you'd like.

    answer = text.trim(term.read(nil, false, nil, "*"))  -- Masking input characters; trim newline

    Note that the one downside to using term.read() is that it will also append a "\n" newline to your input which can cause the input not no match your configured password of course. I resolved this by using the text.trim() to remove it.

     

    Hope this helps.

     

    Cheers!

×
×
  • Create New...

Important Information

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