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

Turning redstone on/off with password

Started by Disturbedsolja, 05 August 2012 - 07:58 PM
Disturbedsolja #1
Posted 05 August 2012 - 09:58 PM
HI guys, I have recently gotten into computercraft with in tekkit and I am still a beginner at this and my friend asked me to write him a simple code where the computer outputs redstone power from the left side by default and can be turned on/off with a password. So i tried my hand at making the program and i got it to output the power and ask for the password but when i put the password in it does nothing at all and the output stays on. If you need anymore information please ask for it and thanks for the help if you do help


term.clear()
term.setCursorPos(1,1)
left = 1
right = 2
password = "off"
while left<right do
rs.setOutput("left", true)
term.clear()
term.setCursorPos(1,1)
print("Password: ")
a = read()
  if a == password then
	left = left + 2
  end
end


Also here is the pastebin link if you want it http://pastebin.com/L4eVG8pJ
Zalerinian #2
Posted 05 August 2012 - 10:33 PM
try this code:


term.clear()
term.setCursorPos(1,1)
rs.setOutput("left", true)
write("Password: ")
pss = read()
if pss = "off" then
rs.setOutput("left", false)
end
write("Password: ")
pss = read()
if pss = "on" then
shell.run("The Program's Name")
end

that *should* work
MysticT #3
Posted 05 August 2012 - 10:46 PM
Try with this:

rs.setOutput("left", true)
while true do
  term.clear()
  term.setCursorPos(1, 1)
  write("Password: ")
  local pass = read("*")
  if pass == "Your Password Here" then
    rs.setOutput("left", not rs.getOutput("left"))
  end
end
Pharap #4
Posted 06 August 2012 - 02:55 AM
Your problem is that you never put the code in to switch the output off

Use this:


password = "off"
rs.setOutput("left", true)
while true do
term.clear()
term.setCursorPos(1,1)
print("Password: ")
a = read()
if a == password then
print("correct")
rs.setOutput("left", false)
sleep(2)
-- put the word return here if you want the program to end after getting the password right
else
print("Incorrect")
sleep(2)
end
end