Am I supposed to have to end every elseif block?

163 views Asked by At

I'm a bit confused about elseif blocks in Lua. On the official Lua tutorial thing it shows that only 1 end is needed for a whole if block. However, in my code, I'm getting an error whenever I don't add a close for every elseif I have in my if. Here's my code with all the ends:

  if direction == 1 then
    snakeHead.y = snakeHead.y - 2
  else if direction == 2 then
    snakeHead.x = snakeHead.x + 2
  else if direction == 3 then
    snakeHead.y = snakeHead.y - 2
  else if direction == 4 then
    snakeHead.x = snakeHead.x - 2
  end
  end
  end
  end

Also, this code is in Love2D although that may be completely unrelated to the issue.

1

There are 1 answers

2
dave On BEST ANSWER

If you read the tutorial you refer to carefully, you will see you need to use elseif and not else if. That is, it's a single keyword, not two.