问题
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
回答1:
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
来源:https://stackoverflow.com/questions/15760576/corona-error-attempt-to-call-global-startbuttonlisteners-a-nil-value