Jump to content




How to make an input = setpassword?


  • You cannot reply to this topic
9 replies to this topic

#1 SNWLeader

  • Members
  • 71 posts
  • LocationTampa Bay, Florida

Posted 30 September 2012 - 04: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?

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 30 September 2012 - 04:20 AM

Does this do what you're looking for?

password = read()


#3 SNWLeader

  • Members
  • 71 posts
  • LocationTampa Bay, Florida

Posted 30 September 2012 - 04:25 AM

View PostLyqyd, on 30 September 2012 - 04:20 AM, said:

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

#4 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 30 September 2012 - 04: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


#5 SNWLeader

  • Members
  • 71 posts
  • LocationTampa Bay, Florida

Posted 30 September 2012 - 04:39 AM

View PostKingdaro, on 30 September 2012 - 04:31 AM, said:

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

#6 Pharap

  • Members
  • 816 posts
  • LocationEngland

Posted 30 September 2012 - 04: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.

#7 SNWLeader

  • Members
  • 71 posts
  • LocationTampa Bay, Florida

Posted 30 September 2012 - 05:02 AM

Actually I need it to set the password of the lock system. how do I get it to do that?

#8 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 30 September 2012 - 05: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.

#9 SNWLeader

  • Members
  • 71 posts
  • LocationTampa Bay, Florida

Posted 30 September 2012 - 05: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.

#10 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 30 September 2012 - 05: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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users