2012-05-02 45 views
22

任何想法为什么这是错误的Lua?if,else,else if and end 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)附近的“其他”

此外,增加每次结束后,如果(这是不是又该做,但试过它)不工作...

如果你需要我翻译成英文我会很乐意做它的评论和一切,但我认为这是不是这个问题的必然性。

+1

这是一个很好的问题。首次开始使用Lua编程时,我遇到了同样的问题! –

+1

哈哈是啊实际上,我习惯于C++和C#所以其他如果似乎对我来说是正确的XD – Makenshi

回答

46

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

查看the manual了解更多信息。

+2

哇错误错误哈哈ty – Makenshi

+1

预期的答案给予许多if/else的替代,如switch语句:-) – 2014-07-22 08:06:05