Hi,
I have a MainMenu containing a Play button and leading to my Game. In my Game scene, I have a “Back” button returning to the MainMenu.
If I try to “Play” again after going back to the main menu, the app crashes with the following:
ERROR: Runtime error bad argument #-2 to 'insert' (Proxy expected, got nil) stack traceback: [C]: in function 'insert' ?: in function 'gotoScene' C:\Users\...\scenes\mainMenu.lua:26: in function '\_onRelease' ?: in function '?' ?: in function '?' ?: in function \<?:190\>
I’ve read several posts from other users but I cannot get to know which call/line causes the issue.
My MainMenu looks like:
local function onPlayButtonRelease(event) composer.gotoScene( "scenes.game") return true -- indicates successful touch end
Here is an extract of my Game file:
function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Load and show the toolbars toolbar.linitializeBottomToolbar() actionbar.initializeActionbar() infobar.initializeTopInfobar() singlebuildingbar.initializeSingleBuildingBar() --sceneGroup:insert( globalData.actionBarGroup ) --sceneGroup:insert( globalData.toolbarGroup) --sceneGroup:insert( globalData.singleBuildingBarGroup) --sceneGroup:insert( globalData.infoBarGroup) --sceneGroup:insert( globalData.resourceBarGroup) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then sceneGroup:removeSelf() -- manually remove backHomeButton sceneGroup = nil globalData.actionBarGroup:removeSelf() -- manually remove globalData.actionBarGroup globalData.actionBarGroup = nil globalData.toolbarGroup:removeSelf() globalData.toolbarGroup = nil globalData.singleBuildingBarGroup:removeSelf() globalData.singleBuildingBarGroup = nil globalData.infoBarGroup:removeSelf() globalData.infoBarGroup = nil globalData.resourceBarGroup:removeSelf() globalData.resourceBarGroup = nil elseif ( phase == "did" ) then end end
And an example of my actionbar/toolbar/topbar being initialized:
local M = {} local globalData = require( "scripts.globalData" )-- Load pseudo global variable to make them accessible from a module to another local widget = require("widget") function M.initializeActionbar() globalData.actionBarGroup = display.newGroup() -- Creates a new display group for the action bar icons globalData.actionBarGroup.alpha = 1 -- Displays the action bar -- Creates the bacHomeButton button globalData.backHomeButton = widget.newButton( { width = 150, height = 150, defaultFile = "images/home.png" } ) globalData.backHomeButton.x = 75 globalData.backHomeButton.y = 320 globalData.actionBarGroup:insert( globalData.backHomeButton ) -- Inserts button into actionbar group end -- initializeActionbar return M
If I uncomment AT LEAST one sceneGroup:insert in the scene:show , the error disapears, but then I have other problems (my Qiso map appears on top of every Composer element, even if it is added to the scene before the different elements).