I’m working on my very first game that I intend to publish with the Corona SDK. I’m currently stuck at an issue that I hope someone here can help me with.
I’m using the composer API to manage scenes, so to show my pause/gameover/win menu’s I turned to the composer.showOverlay() but this is what’s teasing me.
When i run it i get the following error:
Error message:
File: Attempting to load scene from invalid scene module (gameoverlay.lua). Did you forget to return the scene object at the end of the scene module? (e.g. ‘return scene’)
Attempting to load scene from invalid scene module (gameoverlay.lua). Did you forget to return the scene object at the end of the scene module? (e.g. ‘return scene’)
stack traceback:
[C]: in function ‘error’
?: in function ‘showOverlay’
select.lua:82: in function <select.lua:81>
?: in function <?:218>
I’ve replaced the gameoverlay.lua with a clean template found here:http://coronalabs.com/blog/2014/01/21/introducing-the-composer-api-plus-tutorial/
So I’m pretty sure that is not the file causing the trouble.
I’m posting my select.lua, where i placed the showOverlay - I’ve implemented the showOverlay as a button (the level 9) in order to not spoil my gameplay I’m stilling getting the same error, the traceback is just found in different lines.
Hopefully someone can see what I’m doing wrong, because I’m sure it’s a simple typo, or other newbie error
local composer = require("composer" ) local scene = composer.newScene() local myData = require( "myData" ) local physics = require("physics") -- forward refernces local w = display.actualContentWidth local h = display.actualContentHeight -- local objects local background = display.newImage( "bluebg.png" ) background.x = w\*0.5 background.y = h\*0.5 background.width = w background.height = h local backBtn = display.newText({text="\<--BACK", font=system.nativeSystemFont, fontSize=14}) backBtn.x = 50 backBtn.y = 20 --------- LEVELS --------------- local level01 = display.newRect( 50, h\*0.5, 40, 40 ) level01.myLevel = "level"..01 level01:setFillColor( 0, 0, 230 ) local score01 = display.newText( {text=highScores[1], font=system.nativeSystemFont, fontSize=14} ) score01.x = level01.x score01.y = level01.y local level02 = display.newRect( 110, h\*0.5, 40, 40 ) level02.myLevel = "level"..02 level02:setFillColor( 0, 0, 230 ) local score02 = display.newText( {text=highScores[2], font=system.nativeSystemFont, fontSize=14} ) score02.x = level02.x score02.y = level02.y local level03 = display.newRect( 170, h\*0.5, 40, 40 ) level03.myLevel = "level"..03 level03:setFillColor( 0, 0, 230 ) local score03 = display.newText( {text=highScores[3], font=system.nativeSystemFont, fontSize=14} ) score03.x = level03.x score03.y = level03.y local level04 = display.newRect( 230, h\*0.5, 40, 40 ) level04.myLevel = "level"..04 level04:setFillColor( 0, 0, 230 ) local score04 = display.newText( {text=highScores[4], font=system.nativeSystemFont, fontSize=14} ) score04.x = level04.x score04.y = level04.y local level05 = display.newRect( 290, h\*0.5, 40, 40 ) level05.myLevel = "level"..05 level05:setFillColor( 0, 0, 230 ) local score05 = display.newText( {text=highScores[5], font=system.nativeSystemFont, fontSize=14} ) score05.x = level05.x score05.y = level05.y local level06 = display.newRect( 350, h\*0.5, 40, 40 ) level06.myLevel = "level"..06 level06:setFillColor( 0, 0, 230 ) local score06 = display.newText( {text=highScores[6], font=system.nativeSystemFont, fontSize=14} ) score06.x = level06.x score06.y = level06.y local level07 = display.newRect( 410, h\*0.5, 40, 40 ) level07.myLevel = "level"..07 level07:setFillColor( 0, 0, 230 ) local score07 = display.newText( {text=highScores[7], font=system.nativeSystemFont, fontSize=14} ) score07.x = level07.x score07.y = level07.y --funcitons function overLay () composer.showOverlay("gameoverlay", {effect="fade", time=500, isModal=true}) end function goBack () composer.gotoScene("menu", "fade", 500) return true end function levelSelect (event) local gotoLevel = event.target.myLevel composer.gotoScene(gotoLevel, {fade=500}) return true end -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. --Listeners backBtn:addEventListener("touch", goBack ) level01:addEventListener("touch", levelSelect ) level02:addEventListener("touch", levelSelect ) level03:addEventListener("touch", levelSelect ) level04:addEventListener("touch", levelSelect ) level05:addEventListener("touch", levelSelect ) level06:addEventListener("touch", levelSelect ) level07:addEventListener("touch", overLay ) --Scenegroup sceneGroup:insert(background) sceneGroup:insert(backBtn) sceneGroup:insert(level01) sceneGroup:insert(level02) sceneGroup:insert(level03) sceneGroup:insert(level04) sceneGroup:insert(level05) sceneGroup:insert(level06) sceneGroup:insert(level07) sceneGroup:insert(score01) sceneGroup:insert(score02) sceneGroup:insert(score03) sceneGroup:insert(score04) sceneGroup:insert(score05) sceneGroup:insert(score06) sceneGroup:insert(score07) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. physics.start( ) print(highScores[1]) score01.text = highScores[1] end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. background:removeEventListener( "touch", goBack ) end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene