簡體   English   中英

電暈錯誤:嘗試調用全局“ startButtonListeners”

[英]Corona error: attempt to call global “startButtonListeners” <a nil value>

我正在用電暈制作一個主菜單,但是遇到一個錯誤,這使我發瘋。

編譯器使我難以理解它是什么,但是我可以從中指出兩個問題:

  • 嘗試調用全局“ startButtonListeners”
  • 函數“ startButtonListeners”中的[C]

這是代碼部分:

 function scene:enterScene(event)
    local group = self.view 
    startButtonListeners('add')

    function startButtonListeners(action)
      if(action == 'add') then  
         aboutBtn:addEventListener('tap', showCredits)
         startBtn:addEventListener('tap', startBtn)
      end 

      local function onSceneTouch( self, event )
        if event.phase == "began" then
        storyboard.gotoScene( "scene1", fade, 500 )
        return true
      end
    end 
end

將函數startButtonListeners的位置更改為結尾; 函數定義完成后:

scene:enterScene(event)
    local group = self.view 

    function startButtonListeners(action)
      if(action == 'add') then  
         aboutBtn:addEventListener('tap', showCredits)
         startBtn:addEventListener('tap', startBtn)
      end 

      local function onSceneTouch( self, event )
        if event.phase == "began" then
        storyboard.gotoScene( "scene1", fade, 500 )
        return true
      end
    end 
    startButtonListeners('add')
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM