Hi All
I thought I was doing really good! LOL. But I am stopped by errors. I am working on Chapter 5 — Converting the Game to Composer.
I just added the code per the tutorial:
physics.start()
Runtime:addEventListener( “collision”, onCollision )
gameLoopTimer = timer.performWithDelay( 500, gameLoop, 0 )
into the game.lua file. The tutorial says it should look like this:
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == “did” ) then
– Code here runs when the scene is entirely on screen
physics.start()
Runtime:addEventListener( “collision”, onCollision )
gameLoopTimer = timer.performWithDelay( 500, gameLoop, 0 )
end
end
As soon as I add those 3 lines of code, the game crashes when I click the Play button. Here is the error(s)
11:27:46.008 ERROR: Runtime error
11:27:46.008 addEventListener: listener cannot be nil: nil
11:27:46.008 stack traceback:
11:27:46.008 [C]: in function ‘error’
11:27:46.008 ?: in function ‘getOrCreateTable’
11:27:46.008 ?: in function ‘addEventListener’
11:27:46.008 ?: in function ‘addEventListener’
11:27:46.008 ?: in function ‘addEventListener’
11:27:46.008 C:\Users\Andy\Documents\Corona Projects\StarExplorer\menu.lua:76: in function <C:\Users\Andy\Documents\Corona Projects\StarExplorer\menu.lua:65>
11:27:46.008 ?: in function ‘dispatchEvent’
11:27:46.008 ?: in function <?:865>
11:27:46.008 (tail call): ?
11:27:46.008 ?: in function <?:504>
11:27:46.008 ?: in function <?:169>
the strange thing about it is, those three lines of code are NOT in the source code file!
Any ideas?
Thanks