Zac Baker
Zac Baker

Reputation: 37

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:

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

Upvotes: 0

Views: 1353

Answers (1)

hjpotter92
hjpotter92

Reputation: 80657

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

Upvotes: 1

Related Questions