简体   繁体   中英

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

I'm making a main menu scene in corona, however I've come across an error and its driving me crazy.

The compiler makes it confusing for me to understand what it is but I can point out 2 problems from it:

  • attempt to call global "startButtonListeners"
  • [C] in function "startButtonListeners"

Here is the section of code:

 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

Change the location of your function startButtonListeners to the end; after your function definition is complete:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM