I NEED HELP: bad argument #-2 to 'insert' (Proxy expected, got nil)

OK so I got the menu figured out but now when I transition from menu to game to next level to menu and back to game it brings me back to level one which is what I want but it acts like there is objects behind the visible level so everything reacts weirdly. I have tried removing the group but that doesn’t allow me to go back to that level because everything is gone. I have spent about 4 hours on this and I can’t figure it out.

Please help

Avery [import]uid: 184688 topic_id: 33479 reply_id: 133164[/import]

I don’t use storyboards, but in general it sounds like display objects aren’t being removed/hidden…

When displaying one screen after another, some corona objects can behave, errr, unexpectedly if not made invisible, or entirely removed (scroll lists/widgets for example), even if they are behind newer display objects.

Perhaps making the offending objects invisible (the ones that are still active), or ensuring they are removed from the display system (display.remove, object:removeSelf, etc) would solve the issue.

How do you know which ones to deal with in this way you ask? They’re the ones that give you the errors :wink:

[import]uid: 79933 topic_id: 33479 reply_id: 133165[/import]

I was doing a purgeScene on the exitScene event and maybe it’s not a good idea. That was the problem :slight_smile:

For example, this code won’t work:

scene1.lua:
[lua]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

function scene:createScene( event )
local group = self.view

local image = display.newImage( “bg.jpg” )
group:insert( image )

storyboard.gotoScene( “scene2” )
end

function scene:enterScene( event )
local group = self.view
end

function scene:exitScene( event )
local group = self.view
storyboard.purgeScene(“scene1”)
end

function scene:destroyScene( event )
local group = self.view
end

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )

return scene[/lua]

Ways to make it work:

  • Remove the purgeScene on the exitScene event.
    or
  • Remove the image. [import]uid: 46216 topic_id: 33479 reply_id: 133348[/import]

Trying to purge/remove yourself is probably not too good of an idea since you’re deleting yourself. I usually either purge/remove the scene I’m going to before I go to it, so it restarts fresh or I’ll wait until the enterScene phase of the scene I’m going to and remove the previous scene from there. For performance reasons, with the latter, you might want to delay the remove for a couple of seconds using a timer since the removing can be a bit pokey depending on how many assets have to be cleared and if garbage collection is running.
[import]uid: 199310 topic_id: 33479 reply_id: 133360[/import]

You shouldn’t need to remove “group”. Storyboard manages that for you.

Can you describe in better details " but it acts like there is objects behind the visible level so everything reacts weirdly."?

Keep in mind that unless you tell it otherwise, storyboard keeps previous scenes in memory and depending on the transition, it could just be stacking the scenes on top of each other (though a fade or crossFade would render the scene invisible). You can do a storyboard.removeScene(“prevscenename”) to get rid of the previous scene.

Things that do not go into the “group” stay on top of everything. [import]uid: 199310 topic_id: 33479 reply_id: 133201[/import]

do you need quotations around the scenes name? [import]uid: 184688 topic_id: 33479 reply_id: 133261[/import]

The code I posted before is quite more simple and I’m getting the same error. Maybe it’s something related.

The function storyboard.gotoScene should it work if it is inside a performWithDelay callback? Like this:

local function listener()  
 storyboard.gotoScene( scene )  
end  
timer.performWithDelay( 200, listener)  

That’s what I’m doing to get this error. As I said, if I call directly gotoScene without performWithDelay, it works. It’s a bit weird, don’t? [import]uid: 46216 topic_id: 33479 reply_id: 133262[/import]

I finally figured mine out all I have to do is remove the scene previous to the wine I was in every time I enter the scene and it worked so I just put storyboard.removeScene(“prevscenename”) at the beginning of my code and now everything works. I have 1 more question is there a way to “unlock” levels as you beat them. [import]uid: 184688 topic_id: 33479 reply_id: 133263[/import]

The first parameter to the storyboard functions is a string. You can do:

storyboard.gotoScene( “somescene” )

or

scene = “somescene”
storyboard.gotoScene( scene )

[import]uid: 199310 topic_id: 33479 reply_id: 133305[/import]

I was doing a purgeScene on the exitScene event and maybe it’s not a good idea. That was the problem :slight_smile:

For example, this code won’t work:

scene1.lua:
[lua]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

function scene:createScene( event )
local group = self.view

local image = display.newImage( “bg.jpg” )
group:insert( image )

storyboard.gotoScene( “scene2” )
end

function scene:enterScene( event )
local group = self.view
end

function scene:exitScene( event )
local group = self.view
storyboard.purgeScene(“scene1”)
end

function scene:destroyScene( event )
local group = self.view
end

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )

return scene[/lua]

Ways to make it work:

  • Remove the purgeScene on the exitScene event.
    or
  • Remove the image. [import]uid: 46216 topic_id: 33479 reply_id: 133348[/import]

Trying to purge/remove yourself is probably not too good of an idea since you’re deleting yourself. I usually either purge/remove the scene I’m going to before I go to it, so it restarts fresh or I’ll wait until the enterScene phase of the scene I’m going to and remove the previous scene from there. For performance reasons, with the latter, you might want to delay the remove for a couple of seconds using a timer since the removing can be a bit pokey depending on how many assets have to be cleared and if garbage collection is running.
[import]uid: 199310 topic_id: 33479 reply_id: 133360[/import]

I want to perform storyboard.reloadScene on a scene itself, but in order to do that, the “gotchas” say I need to purgeScene within willExitScene or exitScene.

purging within the exitScene will allow a reload to occur.

purging within the willExitScene will do nothing on reload.

Now the problem is when I want to call the gotoScene after a popup event, I get the error “bad argument #-2 to ‘insert’ (Proxy expected, got nil)

Not sure what’s going on here.

I want to perform storyboard.reloadScene on a scene itself, but in order to do that, the “gotchas” say I need to purgeScene within willExitScene or exitScene.

purging within the exitScene will allow a reload to occur.

purging within the willExitScene will do nothing on reload.

Now the problem is when I want to call the gotoScene after a popup event, I get the error “bad argument #-2 to ‘insert’ (Proxy expected, got nil)

Not sure what’s going on here.