Problem with removing a scene.

Hello,

I am new to coding with Corona, and need a bit of help with the project on the ‘Getting Started’ guide. I have finished all existing chapters and then added some of my own stuff.

There is no problem with anything apart from when I try and play the game a second time (i.e. when I try and do either composer.removeHidden() or composer.removeScene( “game” ), the game crashes. The message is:

04:41:52.012  ERROR: Runtime error
04:41:52.012  C:\Users\Matthew\Documents\Corona Projects\StarExplorer\game.lua:87: bad argument #-1 to ‘newImageRect’ (Proxy expected, got nil)
04:41:52.012  stack traceback:
04:41:52.012      [C]: in function ‘newImageRect’
04:41:52.012      C:\Users\Matthew\Documents\Corona Projects\StarExplorer\game.lua:87: in function ‘_listener’
04:41:52.012      ?: in function <?:167>
04:41:52.012      ?: in function <?:169>

 

Line 87 is as follows:

local newAsteroid = display.newImageRect( mainGroup, objectSheet, 1, 102, 85 )

I don’t know if I’m meant to be putting anything in the scene:destroy block, but I don’t remember the guide mentioning it at all.

Thanks in advance for the help,

~Sulphate / Matthew

The error is because the display.newGroup() named mainGroup doesn’t exist.

Removing scene’s is tricky and most likely the:

local mainGroup = display.newGroup()

exists in the scene’s main chunk. Unless you remove the scene correctly, the next time you re-enter, the group won’t be recreated. Since I’m not sure where you left off, if you have a menu.lua, you can call composer.removeScene(“game”) just before you call composer.gotoScene( “game” ) and that will cause the main chunk to be re-executed. Or you can leave:

local mainGroup

in the main chunk and then in scene:create() do:

mainGroup = display.newGroup()

before you use it.

Haha, it turns out that it was me forgetting I added another timer to the code, and forgot to cancel it when removing / hiding the scene in the scene:hide block.

Sorry for being a pain :slight_smile:

The error is because the display.newGroup() named mainGroup doesn’t exist.

Removing scene’s is tricky and most likely the:

local mainGroup = display.newGroup()

exists in the scene’s main chunk. Unless you remove the scene correctly, the next time you re-enter, the group won’t be recreated. Since I’m not sure where you left off, if you have a menu.lua, you can call composer.removeScene(“game”) just before you call composer.gotoScene( “game” ) and that will cause the main chunk to be re-executed. Or you can leave:

local mainGroup

in the main chunk and then in scene:create() do:

mainGroup = display.newGroup()

before you use it.

Haha, it turns out that it was me forgetting I added another timer to the code, and forgot to cancel it when removing / hiding the scene in the scene:hide block.

Sorry for being a pain :slight_smile: