How to properly use the Storyboard API so you can go from your menu to level 1 to level 2 to menu and repeat

I am making a game where:

main.lua sends you to menu.lua

from menu.lua you can go to levelselect.lua

from levelselect.lua you can go to level1.lua

from level1.lua you can either go back to menu.lua or restart level1.lua

However I am having various problems. The first time you run the game, it works fine, everything happens once and the variables are all correct, however if you try to go from level1.lua to menu.lua, weird things start to happen. Everything happens multiple times. I made each “enterScene” function print “entered” to the console and this prints 6 or 7 times.

Also, when you get to the game, the variable goes from 5 to 1 right when you start. Also the physics body, which is a ball with no gravity, randomly moves around as if it is bouncing off things that aren’t there. It changes its speed even though its not supposed to.

I know about the standard storyboard template and that was helpful, but it wasn’t complete. I need a template that is of an actual game (it doesn’t have to be complex) which can go from scene to scene without weird things happenning.

FYI: every scene, after it exits, removes itself, and the destroyScene removes all display objects and sets all variables to nil. Also, physics is enabled.

Attached is my whole project so far with the menu, level select, and level 1. If you want to see the code, look at it.

Check out this link:
http://coronalabs.com/blog/2010/12/10/ghosts-vs-monsters-open-source-game-in-corona-sdk/

@jorgedesa89

Thanks for the link, but that uses director, not storyboard. I would like to use storyboard unless you can give me some good tutorials and documentation on director.

Without seeing some code we can only guess.  But if you’re adding any Runtime: listeners, timers, etc.  They don’t get removed when you leave the scene, even if you call storyboard.removeScene().  If you start something in enterScene() you should stop it in exitScene().   You probably should not “start” things in createScene() or outside of one of the scene functions.  You can create things in createScene().

Also depending on how you have your buttons setup, if you’re using a touch handler, its very possible that you’re not catching the fact they fire multiple times for the different phases of a touch event (“began”, “moved”, “ended”) and if you don’t test for the phase, you can find yourself calling storyboard.gotoScene() multiple times.

Rob

@Rob Miracle

In my eixtScene(), I remove all listeners and when I go to a new scene I do something similar to this:

local function gotolevel1(event)
    if (event.phase==“ended”) then
        print(“level1”)
        storyboard.gotoScene(“level1”)
    end
end

I have now attached my code for anyone to look at.

The code doesn’t show up.

@Rob Miracle

I edited my post where I am asking the question and attached the zip file.

Here is a link to the download though: http://forums.coronalabs.com/index.php?app=core&module=attach&section=attach&attach_id=1925

Perhaps your condition that determines when the level over is still running generating more and more failure events and you are adding multiple touch handlers on the button.

Check out this link:
http://coronalabs.com/blog/2010/12/10/ghosts-vs-monsters-open-source-game-in-corona-sdk/

@jorgedesa89

Thanks for the link, but that uses director, not storyboard. I would like to use storyboard unless you can give me some good tutorials and documentation on director.

Without seeing some code we can only guess.  But if you’re adding any Runtime: listeners, timers, etc.  They don’t get removed when you leave the scene, even if you call storyboard.removeScene().  If you start something in enterScene() you should stop it in exitScene().   You probably should not “start” things in createScene() or outside of one of the scene functions.  You can create things in createScene().

Also depending on how you have your buttons setup, if you’re using a touch handler, its very possible that you’re not catching the fact they fire multiple times for the different phases of a touch event (“began”, “moved”, “ended”) and if you don’t test for the phase, you can find yourself calling storyboard.gotoScene() multiple times.

Rob

@Rob Miracle

In my eixtScene(), I remove all listeners and when I go to a new scene I do something similar to this:

local function gotolevel1(event)
    if (event.phase==“ended”) then
        print(“level1”)
        storyboard.gotoScene(“level1”)
    end
end

I have now attached my code for anyone to look at.

The code doesn’t show up.

@Rob Miracle

I edited my post where I am asking the question and attached the zip file.

Here is a link to the download though: http://forums.coronalabs.com/index.php?app=core&module=attach&section=attach&attach_id=1925

Perhaps your condition that determines when the level over is still running generating more and more failure events and you are adding multiple touch handlers on the button.