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

If then statement not working

Started by WillisDoering, 09 March 2015 - 01:26 AM
WillisDoering #1
Posted 09 March 2015 - 02:26 AM
It keeps returning that line 33 needs a 'then'. There is a 'then' so whats the problem?

rednet.open("top")
disp = peripheral.wrap("right") --insert side of monitor
disp.clear()
-- screen display
disp.setCursorPos(18,1)
disp.write("X")
disp.setCursorPos(1,1)
disp.write("O Forward")
disp.setCursorPos(1,2)
disp.write("O Back")
disp.setCursorPos(10,1)
disp.write("O Left")
disp.setCursorPos(10,2)
disp.write("O Right")
disp.setCursorPos(1,3)
disp.write("O Up")
disp.setCursorPos(1,4)
disp.write("O Down")
disp.setCursorPos(10,3)
disp.write("O Break")
disp.setCursorPos(10,4)
disp.write("O Dig")
disp.setCursorPos(5,5)
disp.write("<- O  O ->")
-- remote commands
while true do
  event, side, x, y = os.pullEvent()
  if x = 18 and y = 1 then
	disp.clear()
	disp.setCursorPos(3,3)
	disp.write("Shutting Down...")
	os.sleep(2)
	os.shutdown()
   else
	rednet.send(7, x)
	rednet.send(7, y)
  end
end
Lyqyd #2
Posted 09 March 2015 - 02:29 AM
The problem is that you're using an assignment operator instead of a comparison operator in your if statement. My favorite sticky post has more details if you need them.
WillisDoering #3
Posted 09 March 2015 - 02:36 AM
How silly of me. Thanks for the help and I'll keep the link for future reference.
Bomb Bloke #4
Posted 09 March 2015 - 02:53 AM
One thing that's worth bearing in mind is that when Lua tells you "expected: such-and-such", what it's really doing is asking "you wrote something which can't go here, did you mean such-and-such?".

The "something which can't go there" typically isn't specified, so it's up to you to read the line and spot the mistake.

What's also worth bearing in mind is that the Lua interpreter is quite flexible in terms of line breaks. This means that if you don't finish a command on one line, it often won't throw an error - it'll simply assume you finished it on the next line, and keep reading. This often in turn leads to another "expected: such-and-such" when that next line doesn't contain the rest of the missing command.