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

then expected? I already wrote it!

Started by faissaloo, 20 December 2013 - 11:41 AM
faissaloo #1
Posted 20 December 2013 - 12:41 PM
So here is my code:

if rs.getInput("Back")=True then
rs.setOutput("Right")=True
sleep(1)
rs.setOutput("Right")=False
sleep(1)
rs.setOutput("Right")=True
sleep(1)
rs.setOutput("Right")=False
rs.setOutput("Back")=False
print("Door opened")
end
if rs.getInput("Back")=False then
rs.setOutput("Left")=True
sleep(1)
rs.setOutput("Left")=False
sleep(1)
rs.setOutput("Left")=True
sleep(1)
rs.setOutput("Left")=False
rs.setOutput("Back")=True
print("Door Closed")
end
But I keep getting the error:
bios:338: [string "door"]:1: 'then' expected
Im not sure why I'm getting this error please help!
Lyqyd #2
Posted 20 December 2013 - 01:45 PM
This error message is covered in the sticky post that should be read before asking questions. Also, you'll want to use true and false instead of True and False. Functions that return booleans can be used by themselves or with a not in conditional statements for the most part.
TheOddByte #3
Posted 20 December 2013 - 01:51 PM
You forgot an '=' and why do you capitalize true, back etc? Those should be lowercased

if rs.getInput("back") == true then
This can also just be

if rs.getInput("back") then
Since it checks if it is true.
Kingdaro #4
Posted 20 December 2013 - 03:26 PM
The script is a little broken in many ways. I've fixed a portion of it, and I think you'll be able to fix the rest on your own. Just know that programming requires a good attention to detail, so if you get an error, double-check the script twice to make sure nothing's wrong.

if rs.getInput("back") then
  rs.setOutput("right", true)
  sleep(1)
  rs.setOutput("right", false)
  sleep(1)
  rs.setOutput("right", true)
  sleep(1)
  rs.setOutput("right", false)
  sleep(1)
  rs.setOutput("right", true)
  print("Door opened")
end