Storyboard Overlay Issue

OK, I have a problem and not sure what is causing it.

I have a game which has a scene called Gamplay.lua.  In this game you can pause the action which opens a overlay scene.  On this overlay I have two buttons.  One button allows the user to restart the level.

I had an issue about how to restart the level so I came up with this idea: -

In gameplay and the user selects Pause: -

storyboard.showOverlay( “pauseOverlay”, options ) is called with the level number as a parameter.

User selects restart.

storyboard.gotoScene( “RestartLevel”, options )  is called.  Now, in the CreateScene event of Restart level I call: -

    local prior_scene = storyboard.getPrevious()

    storyboard.purgeScene( prior_scene )

My understanding is that this will purge both the Gameplay.lua module (??) as the pause screen was shown as an overlay.

The RestartLevel then calls: -

storyboard.gotoScene( “gameplay”, options )

with the level id as a parameter.

The Problem

This works for on iteration.  I start playing, pause the game, click restart and the level resets.  I can then play the level if I want.  If I pause it again (on the second iteration) and click restart I get the error: -

Error Table Expected in the PauseOverlay file.  Complaining about the function insert which can only be the Group:Insert function which is not called when Restart is pressed.  

Has anyone had this problem before?   Is there a better way of restarting a level?  I do not want to try and reset all objects.  It is much quicker just to purge the entire thing and reload.  Any help you can offer would be great!

I have fixed this!  Interestingly the issue appears to have been caused with where I have put the code to reload the Gamplay in the Restart file (???)  The error referenced the PauseOverlay but I think the issue may have just been it was going to quick!

So, I moved the code to reload the Gameplay to the enterScene event: -

function scene:enterScene( event )

    

        print (par.levelid)

        local options =

        {

        params =

        {

        levelid = par.levelid

        }

        }

        storyboard.gotoScene( “gameplay”, options )

end

This must put a very small delay and for some reason that has fixed the issue - on to the next problem now…

I have fixed this!  Interestingly the issue appears to have been caused with where I have put the code to reload the Gamplay in the Restart file (???)  The error referenced the PauseOverlay but I think the issue may have just been it was going to quick!

So, I moved the code to reload the Gameplay to the enterScene event: -

function scene:enterScene( event )

    

        print (par.levelid)

        local options =

        {

        params =

        {

        levelid = par.levelid

        }

        }

        storyboard.gotoScene( “gameplay”, options )

end

This must put a very small delay and for some reason that has fixed the issue - on to the next problem now…