if、else、else if 和 end 在 Lua 中的用法

有任何想法为什么这在 Lua 中是错误的?

       if Pieza == 1 then
            if Rotacion == 1 then
                Piezas = Cuadrado1
            else if Rotacion == 2 then
                Piezas = Cuadrado2
            else if Rotacion == 3 then --这是第273行
                Piezas = Cuadrado3
            else if Rotacion == 4 then
                Piezas = Cuadrado4
            else
                io.write("Me Envio una rotacion que no existe? \n");
            end
--这个end结束第一个if内部的if,即用于比较Rotacion的if
        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
--这个end结束第一个if内部的if,即用于比较Rotacion的if
        else  --这个else是在情况Pieza != 1 || 2的情况下
            io.write("Me Envio una pieza que no existe? \n");
        end --这个end结束整个if(用于比较“Pieza”)

我得到的错误是“期望 'end' (在第273行关闭'if')附近的'then'结束”。

另外,在每个if后面添加end(这不是应该做的事,但尝试了一下)并不起作用...

如果您需要我翻译成英语,我会很乐意做出评论和其他东西,但我认为这对于这个问题来说不是必要的。

原文链接 https://stackoverflow.com/questions/10408704

点赞
stackoverflow用户22364
stackoverflow用户22364

这是 elseif,而不是 else if(注意空格)。错误是因为解释器期望每个 else 块都有一个 end

有关更多信息,请参见 手册

2012-05-02 06:32:36