2012-05-02 14 views
22

Qualche idea del perché questo è sbagliato in Lua?se, altrimenti, se e fine 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") 

L'errore che sto ottenendo è questa 'fine' previsto (per chiudere 'se' at line 273) nei pressi di 'altro'

Inoltre, l'aggiunta di fine dopo ogni caso (questo non è ciò che dovrebbe sii fatto ma lo provai comunque) non funziona ...

Se hai bisogno di me per tradurre in inglese, farò volentieri commenti e tutto ma non pensavo che fosse necessario per questa domanda.

+1

Questa è una buona domanda. Ho avuto lo stesso problema quando ho iniziato a programmare con Lua! –

+1

haha ​​sì in realtà sono abituato a C++ e C# così altro se sembra corretto per me XD – Makenshi

risposta

46

È elseif, non else if (notare lo spazio). L'errore è perché l'interprete si aspetta un end per ogni blocco else.

Vedere the manual per ulteriori informazioni.

+2

wow errore noob hahayy – Makenshi

+1

Previsto una risposta che fornisce un'alternativa a molti se/else come un'istruzione switch :-) –

Problemi correlati