Corona错误:尝试调用全局变量“startButtonListeners”,<a nil value>。

我在 corona 中制作主菜单场景,然而我遇到了一个错误,让我感到疯狂。

编译器让我难以理解它是什么,但我可以从中指出两个问题:

  • 尝试调用全局“startButtonListeners”
  • [C] 在函数“startButtonListeners”中

这是代码的一部分:

 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
点赞
用户1190388
用户1190388

将你的函数 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
2013-04-02 12:05:06