Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果,否则,如果和结束Lua_Lua_If Statement - Fatal编程技术网

如果,否则,如果和结束Lua

如果,否则,如果和结束Lua,lua,if-statement,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

你知道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")
我得到的错误是这个“结束”预期(在第273行关闭“如果”)靠近“其他”

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


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

它是
elseif
,而不是
else If
(注意空格)。错误是因为解释器希望每个
else
块都有
end


有关更多信息,请参阅。

这是一个好问题。我第一次用Lua编程时也遇到了同样的问题!哈哈,是的,实际上我习惯了C++和C语言,所以,如果对我来说似乎是正确的XXEPPLICATION一个答案,它给出了许多IF的替代,比如开关语句:- Lua没有开关语句。