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

code help with a frame motor door

Started by trevor1097, 11 December 2012 - 02:59 PM
trevor1097 #1
Posted 11 December 2012 - 03:59 PM
i was working on a door lock using frames and i can get in but i cant get out due to the computer being on the other side of the door. came someone help me with the code so i can get out of the door from the other side.

pass = ("welcome")
dubug = ("edit")
print ("Welcome to Trevor1097's Castle")
print ("These Doors Are Locked")
print ("Enter The Password")
write "password: "
input = read("*")
if input == pass then
print ("Welcome gates are opening")
shell.run("redpulse","left","2",".75")
print ("Enter the gates")
sleep(3)
shell.run("redpulse","right","2",".75")
print ("Gates locked")
os.reboot()
elseif input == dubug then
print ("editing")
os.clear()
else
print ("wrong password")
sleep(1)
os.reboot()
end
rs.getinput("top" true) == true then
shell.run("redpulse","left","2",".75")
sleep(3)
shell.run("redpulse","right","2",".75")
os.reboot()
on the line 26
rs.getinput("top" true) == true then
i get the error message
bios:206: [string "door"]:26: ')' expected

any help that i get i would like to thank you
etopsirhc #2
Posted 11 December 2012 - 04:09 PM
your missing the comma on that line
trevor1097 #3
Posted 11 December 2012 - 05:41 PM
on which line does this go on
Bubba #4
Posted 11 December 2012 - 05:54 PM
on which line does this go on
Line 26. The line you have rs.getInput("top" true)
It needs to be (exactly as shown, with capitals and all):

rs.getInput("top", true)

Lua is case-sensitive, so if you leave out the capitals then it won't recognize rs.getInput as a function.

Also I believe that the line that has os.clear() should be term.clear() instead. os.clear() is not a function.
trevor1097 #5
Posted 12 December 2012 - 10:16 AM
thanks that solved that problem but it is sopose to open with either the password or the redstone signal
Bubba #6
Posted 12 December 2012 - 10:51 AM
thanks that solved that problem but it is sopose to open with either the password or the redstone signal

What do you mean? You mean it needs to open for a redstone signal as well as the password? Could you post a screenshot of your setup?
trevor1097 #7
Posted 12 December 2012 - 04:17 PM
ok it is a little compact but a can give you a easyer pic
trevor1097 #8
Posted 12 December 2012 - 04:54 PM
the top is the real one and the bottom one is a symple breakdown of the wires as in the code. top is from the back side
Bubba #9
Posted 12 December 2012 - 05:36 PM
Okay I think I understand what you mean now. The easiest way to go about this is probably using the parallel api like the following:

local function getUserInput() --Gets user input
  term.clear()
  term.setCursorPos(1,1)
  term.write("Password: ")
  local input = read()
  if input == "password" then
    rs.setOutput("left", true)
    sleep(3)
    rs.setOutput("left", false)
  else
    print("Wrong password.")
    sleep(5)
  end
  return true
end

local function getRedstoneInput() --Waits for redstone to turn on or off
  os.pullEvent("redstone")
  if rs.getInput("top") == true then
    print("Opening door from redstone")
    rs.setOutput("left", true)
    sleep(3)
    rs.setOutput("left", false)
  end
  return true
end


while true do
  parallel.waitForAny(getUserInput, getRedstoneInput) --Waits for either the getUserInput function to finish or getRedstoneInput function to finish
end
trevor1097 #10
Posted 13 December 2012 - 08:20 AM
Is it possible to put in the debug key and how do you set the password
Bubba #11
Posted 13 December 2012 - 09:05 AM
Is it possible to put in the debug key and how do you set the password

Just change the getUserInput() function to accept a debug key and change the password value in the if statement.
trevor1097 #12
Posted 13 December 2012 - 10:01 AM
ok thanks but the redpulse on the password key doesnt work
also what command could i put under the elseif input (debug) so i could edit the computer


local function getUserInput()
  term.clear()
  term.setCursorPos(1,1)
  term.write("Password: ")
  local input = read("*")
  if input == "welcome" then
	shell.run("redpulse","left","2",".75")
	print("Enter the gates")
	sleep(3)
	shell.run("redpulse","right","2",".75")
  elseif input == "edit" then
	print ("editing")
	sleep(2)
  else
	print("Wrong password")
	sleep(5)
  end
  return true
end
local function getRedstoneInput()
  os.pullEvent("redstone")
  if rs.getInput("top") == true then
	print("Opening door from redstone")
	shell.run("redpulse","left","2",".75")
	print ("Enter the gates")
	sleep(3)
	shell.run("redpulse","right","2",".75")
  end
  return true
end
while true do
  parallel.waitForAny(getUserInput, getRedstoneInput)
end