Problem with reloading the scene, using storyboard API.

Hi,

I managed to restart my current scene with

storyboard.purgeScene("vertical\_sixty\_seconds") storyboard.reloadScene()

Also note that I make my restart button in createScene, as I supposed to do. Problem is, if I press restart button fast several times, like 7 or 8,  in a row game breaks, saying that:

attempt to call method 'setTextColor' (a nil value)

Before this, it was saying that insert method of current scene object was not defined.

Strange thing is that I’m calling function via registering it to enterFrame event at last line of enterScene code, so I think it’s safe to assume that we do have our scene object, right?

Strange thing is, everything is fine if you press the restart button slowly, game only breaks if you press it fast.

Thanks.

I resorted to make a temp scene so I just transit there and quickly get back to the current scene and just purge the previous scene and “goto” there. But even then, if I press the restart button several times, game acts funny.

Grr, what’s the best way to reload a scene? Is it this hard?

I’m following guide lines of storyboard, but still face these problems, very frustrating.

Have you tried cancelling the runtime listener before you exit the scene? Otherwise, it may still be running as you enter ie(running x2)

Yes"

function sceneGroup:exitScene( event ) local group = self.view ----------------------------------------------------------------------------- -- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.) ----------------------------------------------------------------------------- Runtime:removeEventListener("enterFrame", MainLoop); Runtime:removeEventListener("enterFrame", incrementalScoreIncrease) -- Runtime:removeEventListener("enterFrame", UpdateHUD) end

Any ideas?

Well to be honest I didn’t dig very deeply into this matter. I tried reloading a scene, but it didn’t work as I expected so I made my own “reloader”

I have an object with the scene elements(which is a display object). When I want to reload the scene, I just remove that object + listeners, and instantiate it again.

Thanks for the reply.

Thing is, I have a lot of things that I have to do this for and there is a reload mechanism builtin there which I believe will run much faster than my own way because it will call a native Corona call and run at machine code speed rather than scripting level.

Would someone with a working reload mechanism test their reload by pressing it several times to see whether if it crashes or not please? Maybe problem is under the hood and what I’m doing is right.

I’m still dealing with this. Another question, does gotoScene / reloadScene call get to actually work exactly when it’s called or it will be queued and gets to be called after a time?

I resorted to make a temp scene so I just transit there and quickly get back to the current scene and just purge the previous scene and “goto” there. But even then, if I press the restart button several times, game acts funny.

Grr, what’s the best way to reload a scene? Is it this hard?

I’m following guide lines of storyboard, but still face these problems, very frustrating.

Have you tried cancelling the runtime listener before you exit the scene? Otherwise, it may still be running as you enter ie(running x2)

Yes"

function sceneGroup:exitScene( event ) local group = self.view ----------------------------------------------------------------------------- -- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.) ----------------------------------------------------------------------------- Runtime:removeEventListener("enterFrame", MainLoop); Runtime:removeEventListener("enterFrame", incrementalScoreIncrease) -- Runtime:removeEventListener("enterFrame", UpdateHUD) end

Any ideas?

Well to be honest I didn’t dig very deeply into this matter. I tried reloading a scene, but it didn’t work as I expected so I made my own “reloader”

I have an object with the scene elements(which is a display object). When I want to reload the scene, I just remove that object + listeners, and instantiate it again.

*shy self bump*

Thanks for the reply.

Thing is, I have a lot of things that I have to do this for and there is a reload mechanism builtin there which I believe will run much faster than my own way because it will call a native Corona call and run at machine code speed rather than scripting level.

Would someone with a working reload mechanism test their reload by pressing it several times to see whether if it crashes or not please? Maybe problem is under the hood and what I’m doing is right.

Would someone please test reload in their apps to see if they reload like 5-8 times in a row, would it break the game or not.

I’ve been pulling my hair for so long over this.

Thanks.

I’m still dealing with this. Another question, does gotoScene / reloadScene call get to actually work exactly when it’s called or it will be queued and gets to be called after a time?

I think I’ve read all the posts on this forum, and possibly on google, that has corona and reload keywords on it!

Figured that there _was_ a problem with Corona SDK regarding this and recently been patched, so I updated my build. Then since I will eventually need transition for reload, I settled for intermediate screen but I have a problem with it:

If I set physics.setDrawMode( “hybrid”) and reload, I can see the physic objects attached to my display images from previous scene, not the display images themselves!

Do I have to attach physic objects that are attached to display images to the storyboard’s view separately? Because I AM attaching display images to storyboard’s view and I thought by attaching physic to them, they would get attached as well. But then again, physic bodies are related to box2D world and not Corona but Storyboard is Corona side.

But then again, in intermediate screen I’m purging (or removing, no matter which one) the previous screen, so why physic entities still lurk there?

By the way here is my intermediate screen:

 local storyboard = require("storyboard") local scene = storyboard.newScene() --------------------------------------------------------------------------------- -- STORYBOARD FUNCTIONS --------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene(event) local localGroup = self.view local r = display.newRect(0, 0, 10, 10) localGroup:insert(r) r:setFillColor(0,0,0) end -- Called immediately after scene has moved onscreen: function scene:enterScene(event) local group = self.view local previous = storyboard.getPrevious() if previous ~= "main" and previous then -- storyboard.removeScene(previous) storyboard.purgeScene(previous) end local ready = function() storyboard.gotoScene("vertical\_sixty\_seconds", "fromBottom", 300); end timer.performWithDelay(50, ready) end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) --------------------------------------------------------------------------------- return scene 

Thanks guys.