Composer and showOverlay not working properbly

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 :wink: 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 :slight_smile:

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

I think we are going to need to see your overlay scene.

local composer = require( "composer" ) local scene = composer.newScene() local myData = require("myData") --------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE -- unless "composer.removeScene()" is called. --------------------------------------------------------------------------------- -- local forward references should go here --------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. 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. 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. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

Your overlay scene doesn’t seem to do any thing.  Try putting at least something in the scene:create() function.

What happens if you try to just to a “gotoScene” to it?  Maybe for testing have your main.lua jump straight to the overlay scene

First i just made a display.newRect() to add something on it, and I got the same error displayed abov, so i replaced it with a blank template to make sure that it wasn’t any of my coding that was causeing it. 

I can use gotoScene without a problem. I have a main.lua file, which goes to a level.lua where you can go to 7 different levels. I can play the first level, complete it, go back to the main menu and restart the game, without a problem. 

It’s only when i use the composer.showOverlay() that this error occurs. I’ve also tried moving the overlay to different levels and stuff, which didn’t help either. 

I can’t upload my project to this site, but if I’d help you I can upload it to some upload site(dropbox or something) 

On its own your scene works if you remove the stuff that we don’t have.

The differences between a scene and an overlay are fairly small. Have you tried running your overlay as a scene ?

I had a similar problem which was down to not returning true after handling events, they were passed onto the parent which caused all sorts of weird effects ? 

When I try opening the gameoverlay.lua with [lua]composer.gotoScene()[/lua]

it gives me this error: 

“Attempt to concatenate global ‘sceneName’ (a nil value)” - I am so embarrassed! and I found the solution because of it. 
 

SOLUTION

I somehow managed to make a copy of an empty gameoverlay.lua and place it in my project folder, while the correct gameoverlay.lua that I’ve been working on was placed in another directory *Major facepalm*. 

Anyhows, it all works perfectly now! :) 

I think we are going to need to see your overlay scene.

local composer = require( "composer" ) local scene = composer.newScene() local myData = require("myData") --------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE -- unless "composer.removeScene()" is called. --------------------------------------------------------------------------------- -- local forward references should go here --------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. 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. 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. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene

Your overlay scene doesn’t seem to do any thing.  Try putting at least something in the scene:create() function.

What happens if you try to just to a “gotoScene” to it?  Maybe for testing have your main.lua jump straight to the overlay scene

First i just made a display.newRect() to add something on it, and I got the same error displayed abov, so i replaced it with a blank template to make sure that it wasn’t any of my coding that was causeing it. 

I can use gotoScene without a problem. I have a main.lua file, which goes to a level.lua where you can go to 7 different levels. I can play the first level, complete it, go back to the main menu and restart the game, without a problem. 

It’s only when i use the composer.showOverlay() that this error occurs. I’ve also tried moving the overlay to different levels and stuff, which didn’t help either. 

I can’t upload my project to this site, but if I’d help you I can upload it to some upload site(dropbox or something) 

On its own your scene works if you remove the stuff that we don’t have.

The differences between a scene and an overlay are fairly small. Have you tried running your overlay as a scene ?

I had a similar problem which was down to not returning true after handling events, they were passed onto the parent which caused all sorts of weird effects ? 

When I try opening the gameoverlay.lua with [lua]composer.gotoScene()[/lua]

it gives me this error: 

“Attempt to concatenate global ‘sceneName’ (a nil value)” - I am so embarrassed! and I found the solution because of it. 
 

SOLUTION

I somehow managed to make a copy of an empty gameoverlay.lua and place it in my project folder, while the correct gameoverlay.lua that I’ve been working on was placed in another directory *Major facepalm*. 

Anyhows, it all works perfectly now! :)