lua - if, else, else if and end Lua

标签 lua if-statement

知道为什么这在 Lua 中是错误的吗?

       if Pieza == 1 then
            if Rotacion == 1 then
                Piezas = Cuadrado1
            else if Rotacion == 2 then
                Piezas = Cuadrado2
            else if Rotacion == 3 then --this is Line 273
                Piezas = Cuadrado3
            else if Rotacion == 4 then
                Piezas = Cuadrado4
            else
                io.write("Me Envio una rotacion que no existe? \n");
            end 
--this end closes the if inside the first if the one using to compare Rotacion
        else if Pieza == 2 then
            if Rotacion == 1 then
                Piezas = I1
            else if Rotacion == 2 then
                Piezas = I2
            else if Rotacion == 3 then
                Piezas = I3
            else if Rotacion == 4 then
                Piezas = I4
            else
                io.write("Me Envio una rotacion que no existe? \n");
            end
--this end closes the if inside the first if the one using to compare Rotacion
        else  --this else is in case Pieza != 1 || 2
            io.write("Me Envio una pieza que no existe? \n");
        end --this close the whole if (the one comparing "Pieza")

我得到的错误是'else'附近的'end'预期(在第273行关闭'if')

此外,在每个 if 之后添加 end (这不是应该做的,但无论如何都尝试过)不起作用......

如果你需要我翻译成英语,我很乐意做评论和所有事情,但我认为这个问题不是必需的。

最佳答案

它是 elseif ,不是 else if (注意空格)。错误是因为解释器需要 end每个else堵塞。

the manual想要查询更多的信息。

关于lua - if, else, else if and end Lua,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10408704/

相关文章:

c - Lua C编译-llua错误

macos - 无法在 osx yosemite 上进行枪战。 undefined symbol

excel - R 中的 IF 语句 - 始终嵌套?

Java if 语句不满足

使用枚举、方法和用户输入更新的 Java Suit 应用程序

iphone - 从 iOS 应用调用 Lua 脚本

windows - LuaSocket 套接字/core.dll 需要的位置?

Lua:gsub:无法将捕获的数字字符串处理为数字

java - 尽量减少 if 语句的使用

javascript - 空数组在比较时返回 false 但当它单独返回 true 时......为什么这样