【问题标题】:Corona error: attempt to call global "startButtonListeners" <a nil value>电晕错误:尝试调用全局“startButtonListeners”<a nil value>
【发布时间】:2013-04-02 20:05:06
【问题描述】:

我正在电晕中制作一个主菜单场景,但是我遇到了一个错误,这让我发疯了。

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

  • 尝试调用全局“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

【问题讨论】:

  • 你应该在使用它之前定义你的函数。
  • 你的函数onSceneTouch 是无用的,因为它只在startButtonListeners 中可见,并且没有在那里使用。
  • 抱歉,我还在学习中...如果您可以编辑代码以显示它应该是什么样子,是否可以?

标签: lua coronasdk


【解决方案1】:

把你的函数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

【讨论】:

    猜你喜欢
    • 2018-07-04
    • 2019-08-21
    • 2021-08-04
    • 2019-09-23
    • 2018-07-11
    • 2019-06-13
    • 2014-05-06
    • 2022-11-23
    • 2021-09-04
    相关资源
    最近更新 更多