2013-03-10 24 views
0

我試圖創建2個不同的功能NCAR表:設置ANS main_frame如何在一個表lua中創建多個函數? (電暈SDK)

local ncar= 
{ 
    img=display.newImageRect("test_car.png",50,120,true); 
    x=0; 
    y=0; 
    frames=0; 
    setup=function(self) 
     return self; 
    end 
    main_frame=function(self) 
     self.frames=self.frames+1; 
     return function(event) 
      self.img.x=self.x; 
      self.img.y=self.y; 
     end 
    end 

} 

但是編譯器說,他希望看到「}」,其中第二個函數(main_frame在這種情況下)開始,當我添加它。原因是什麼?

回答

3

setup函數定義後需要逗號或分號。
這是因爲您要通過列出其字段來創建表格,這些字段應該彼此分開。

+0

瘋狂,我不知道Lua允許分號作爲字段分隔符+1 – dualed 2013-03-10 12:08:41