This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
SNWLeader's profile picture

How to make an input = setpassword?

Started by SNWLeader, 30 September 2012 - 03:16 AM
SNWLeader #1
Posted 30 September 2012 - 05:16 AM
I am working on a Disk that would program the startup to a locking program, but I need to beable to make whatever you need to input to be read then set to variable. How would I need to do that?
Lyqyd #2
Posted 30 September 2012 - 05:20 AM
Does this do what you're looking for?


password = read()
SNWLeader #3
Posted 30 September 2012 - 05:25 AM
Does this do what you're looking for?


password = read()

that is not it I need it to take the input and put that input on a variable
Kingdaro #4
Posted 30 September 2012 - 05:31 AM
That's exactly what read() does. If your variable is named "input", then do:

input = read()

An applicable example:

password = 'yourpassword'

while true do
  term.clear()
  term.setCursorPos(1,1)
  print 'Password?'
  input = read()
  if input == password then
    print 'Access Granted'
    rs.setOutput('left', true)
    sleep(3)
    rs.setOutput('left', false)
  else
    print 'Access Denied'
  end
end
SNWLeader #5
Posted 30 September 2012 - 05:39 AM
That's exactly what read() does. If your variable is named "input", then do:

input = read()

An applicable example:

password = 'yourpassword'

while true do
  term.clear()
  term.setCursorPos(1,1)
  print 'Password?'
  input = read()
  if input == password then
	print 'Access Granted'
	rs.setOutput('left', true)
	sleep(3)
	rs.setOutput('left', false)
  else
	print 'Access Denied'
  end
end


I am making a disk to program that automatically into a computer as a startup
Pharap #6
Posted 30 September 2012 - 05:53 AM
So are you asking how to get the user's input or how to copy a program from the disk to the computer as the disk's startup routine?

If you want the input thing:

input = read() --input will then become whatever the user types before pressing enter

if you want the copy thing

shell.run("copy", "disk/password", "startup") --copies the program 'password' on the disk onto the computer as a the program 'startup'

Any program called startup will be run when a computer or turtle boots up.
if there is a disk in a disk drive and it contains a program called startup, that program will have priority over the computer's startup program.
SNWLeader #7
Posted 30 September 2012 - 06:02 AM
Actually I need it to set the password of the lock system. how do I get it to do that?
Lyqyd #8
Posted 30 September 2012 - 06:15 AM
Oh, so you want it to write a program file to the computer, setting a variable declared inside that program file to whatever the user enters? You'll want to use a multi-line string, then add the line with user input where appropriate.
SNWLeader #9
Posted 30 September 2012 - 06:20 AM
well my problem is I need it to print the variable in this command

in here
fs.open("startup","w").writeLine("password = _____")

what happens to me if say the variable is A then in the document it says just A. i need it to input what A equals.
Lyqyd #10
Posted 30 September 2012 - 06:52 AM
Try this:


print("Input password, please")
local pass = read("*")
handle = fs.open("startup", "w")
if handle then
    handle.writeLine([[local password = "]]..pass..[["]])
    handle.write([[    while true do
        term.clear()
        term.setCursorPos(1, 1)
        print("Input Password:")
        input = read("*")
        if input == password then openDoorOrWhatever() end
    end]])
    handle.close()
end