[Resolved] storyboard.gotoScene vs. reloadScene

hm. don’t know if I just have not read a particular blog post on this…

… but when I created my in-game-menu with an older corona build, I was able to reload my game scene just by calling

storyboard.gotoScene ( "game" , "fade" )  

scene:destroyScene was invoked, the scene reloaded and everything worked fine.
However, I need the iOS6 fix and therefore I built my game with the latest corona build.
And now the game scene view just stays on the screen after scene:exitScene(event) is invoked…

I tried to purge and to remove the game scene inside the exitScene event.
and it looks like createScene is invoked after that, but when an object is inserted to self.view the game crashes. An error on the line where I insert something to the scene view fires

bad argument #-2 to 'insert' (Proxy expected, got nil)  

it looks like my display group that I grab from another module is nil.

stragely enough, when I go back to the main menu scene and restart the game from there, everything works fine…

what did I miss? [import]uid: 70635 topic_id: 31887 reply_id: 331887[/import]

also, the doc for reloadScene talks about a willExitScene-event that isn’t documented anywhere…
-> http://docs.coronalabs.com/api/library/storyboard/reloadScene.html

[import]uid: 70635 topic_id: 31887 reply_id: 127213[/import]

okay, here’s an example that shows the problem [SOLVED]:

[code]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

local var1
local var2
local var3

local theTimer

function scene:createScene( event )

var1 = 1 – must reset vars here
var2 = “String”
var3 = “Start new String”

local group = self.view
var3 = var3…" + end new String"
print (var1…" / “…var2…” / "…var3)
end

function scene:willEnterScene( event )
local group = self.view
print (“willEnterScene”)
end

function scene:enterScene( event )
local group = self.view
print (“enterScene”)

local function wrap1 ()
print ("getCurrentSceneName: "…storyboard.getCurrentSceneName())
storyboard.purgeScene(“scene1”)
storyboard.gotoScene( “scene1”, “fade”, 1500 )
end

var1 = 1000 – vars have changed during game
var2 = “It’s the String! But now it’s different!”
var3 = “_something has changed!_”

timer.performWithDelay( 1000, wrap1, 1 )
end

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

function scene:didExitScene( event )
local group = self.view
print (“didExitScene”)
end

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

function scene:overlayBegan( event )
local group = self.view
local overlay_name = event.sceneName
end

function scene:overlayEnded( event )
local group = self.view
local overlay_name = event.sceneName
end

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “willEnterScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “didExitScene”, scene )
scene:addEventListener( “destroyScene”, scene )
scene:addEventListener( “overlayBegan”, scene )
scene:addEventListener( “overlayEnded”, scene )

return scene
[/code]

I want to reload the scene from inside the scene (while the scene is being displayed).
I want all local vars to reset, i.e. the whole scene module. I’m beginning to think that this is a bug, because it worked fine in an older corona sdk build… :frowning:

Any ideas?

EDIT: updated the code above, where it works. still have problems in the reloaded module…

EDIT II: okay. my fault! I take back the “bug”.

I had this lua module that was directly returning a display group.
like this:

local myGroup = display.newGroup()  
-- creating a display object  
-- insertin ig to group  
return myGroup  

it works! (once.)
I turned it to this

local myGroupTable = {}  
myGroupTable.grabGroup = function()  
 local myGroup = display.newGroup()  
 -- creating a display object  
 -- insertin ig to group  
 return myGroup  
end  
return myGroupTable  

now everything works fine. [import]uid: 70635 topic_id: 31887 reply_id: 127223[/import]

also, the doc for reloadScene talks about a willExitScene-event that isn’t documented anywhere…
-> http://docs.coronalabs.com/api/library/storyboard/reloadScene.html

[import]uid: 70635 topic_id: 31887 reply_id: 127213[/import]

okay, here’s an example that shows the problem [SOLVED]:

[code]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

local var1
local var2
local var3

local theTimer

function scene:createScene( event )

var1 = 1 – must reset vars here
var2 = “String”
var3 = “Start new String”

local group = self.view
var3 = var3…" + end new String"
print (var1…" / “…var2…” / "…var3)
end

function scene:willEnterScene( event )
local group = self.view
print (“willEnterScene”)
end

function scene:enterScene( event )
local group = self.view
print (“enterScene”)

local function wrap1 ()
print ("getCurrentSceneName: "…storyboard.getCurrentSceneName())
storyboard.purgeScene(“scene1”)
storyboard.gotoScene( “scene1”, “fade”, 1500 )
end

var1 = 1000 – vars have changed during game
var2 = “It’s the String! But now it’s different!”
var3 = “_something has changed!_”

timer.performWithDelay( 1000, wrap1, 1 )
end

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

function scene:didExitScene( event )
local group = self.view
print (“didExitScene”)
end

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

function scene:overlayBegan( event )
local group = self.view
local overlay_name = event.sceneName
end

function scene:overlayEnded( event )
local group = self.view
local overlay_name = event.sceneName
end

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “willEnterScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “didExitScene”, scene )
scene:addEventListener( “destroyScene”, scene )
scene:addEventListener( “overlayBegan”, scene )
scene:addEventListener( “overlayEnded”, scene )

return scene
[/code]

I want to reload the scene from inside the scene (while the scene is being displayed).
I want all local vars to reset, i.e. the whole scene module. I’m beginning to think that this is a bug, because it worked fine in an older corona sdk build… :frowning:

Any ideas?

EDIT: updated the code above, where it works. still have problems in the reloaded module…

EDIT II: okay. my fault! I take back the “bug”.

I had this lua module that was directly returning a display group.
like this:

local myGroup = display.newGroup()  
-- creating a display object  
-- insertin ig to group  
return myGroup  

it works! (once.)
I turned it to this

local myGroupTable = {}  
myGroupTable.grabGroup = function()  
 local myGroup = display.newGroup()  
 -- creating a display object  
 -- insertin ig to group  
 return myGroup  
end  
return myGroupTable  

now everything works fine. [import]uid: 70635 topic_id: 31887 reply_id: 127223[/import]