我应该结束每个elseif块吗?
问题描述:
我对Lua中的elseif块有些困惑。在official Lua tutorial thing上,它显示整个if块只需要1个末端。但是,在我的代码中,每当我没有为我在if中的每个elseif添加close时,都会收到错误。这里是我所有的代码:我应该结束每个elseif块吗?
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
此外,这段代码是在Love2D,虽然这可能是完全无关的问题。
尝试将'else if'更改为'elseif',即。失去两个关键字之间的空间。 – dave
你正在创建嵌套if语句的'else'块,不使用'elseif' – warspyking