电晕错误:试图调用全球的“startButtonListeners”(Corona error: a

2019-10-29 14:19发布

我在电晕制作主菜单中的场景,但我遇到一个错误,它的驾驶我疯狂。

编译器可以十分困惑,我理解它是什么,但我可以指出,从它2个问题:

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

Answer 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


文章来源: Corona error: attempt to call global “startButtonListeners”