Question

I'm simply trying to use the composer.showOverlay() to display game-over, pause menu's etc.

I'm using the composer.showOverlay("gameoverlay",options) to call the overlay when a scene ends(Timer goes to zero etc), but I'm getting an error telling me I'm trying to call a wrong module, like my pause.lua isn't properbly formatted It looks like this

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()"unction scene:hide( event )
function scene:hide( event )
   local sceneGroup = self.view
   local phase = event.phase
   local parent = event.parent  --reference to the parent scene object

   if ( phase == "will" ) then
      -- Call the "resumeGame()" function in the parent scene

   end
end

-- By some method (a "resume" button, for example), hide the overlay
-- composer.hideOverlay( "fade", 400 )

scene:addEventListener( "hide", scene )
return scene

    local sceneGroup = self.view

    -- Initialize the scene here.
    -- Example: add display objects to "sceneGroup", add touch listeners, etc

    local background = display.newRect( 0, 0, display.actualContentHeigh, display.actualContentWidth
    bacground:setFillColor( black ) )







-- -------------------------------------------------------------------------------

-- Listener set)

-- -------------------------------------------------------------------------------

return scene

This is far from the only version of the gameoverlay.lua I have used. I also tried using the normal setup for composer scenes. scene:create scene:show scene:hide scene:destroy.

Still got the same error which looks like

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')
Was it helpful?

Solution 2

The file gameoverlay.lua that I was trying to run through the composer.showOverlay() was an empty file, and the gameoverlay.lua that I was working on was placed in a wrong directory Major facepalm.

If run with the composer.gotoScene() I would get a error saying that the "sceneName" was a nil value(because it was empty).

Solution Make sure that the file is not empty, and is requiring composer and has a proper composer scene setup.

OTHER TIPS

You have two returns in your code, so the portion that creates the sceneGroup will not be run. Secondly, I think that Lua throws an error and this module does not get loaded, so the scene is never returned and hence your error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top