Restart.lua with weird results

Hi guys, I have a game I am making and i have a retry button. When I click the retry button, it goes to a restart.lua and then back to game.lua

This works fine the first time, however the second time, the player moves at twice the speed with 2 player images. 1 stays still and the other flys fast. Then every restart after that doubles the speed of the player.

This function is called when the try again button is pressed

    function tryAgain(event, stage)         if(event.phase == "ended")then             storyboard.gotoScene("restart",{time=200,effect="fade", params={}})         end     end

Then this is whats in the restart.lua file

local storyboard = require "storyboard" local scene = storyboard.newScene() function scene:enterScene(event)     storyboard.removeAll()     local function removeOld()         storyboard.gotoScene("game",{effect="fade",time=500})     end     timer.performWithDelay(100,removeOld,1) end scene:addEventListener("enterScene",scene) return scene

With using remove all, I do not understand why its not deleting the scene and starting afresh.

EDIT: I have found out that the main loop is running twice on those times it errors. I need to somehow remove the main loop.

The main loop works the normal way.

local function main( event )     --super secret code end Runtime:addEventListener( "enterFrame", main)

I do also have this bit in there too

function scene:destroyScene(e)     Runtime.\_functionListeners = nil     allPlatforms = {} end scene:addEventListener("destroyScene",scene)

@Tom Hanson, its hard to help without seeing the complete code. Putting only part of it and ask the community to give you hint,  is a tough call. This being said, and based on your observation I would verify that you do not call twice Runtime:addEventListener( “enterFrame”, main) before ensuring you always remove first the event listener…

Also, why do you still use the obsolete Storyboard ? You should move to Composer.

Thanks for the reply. Yeah in my search I found that Storyboard was obsolete so I am in the process of converting the whole thing. And thanks for the suggestion. I will check to see if that is happening. Thank you

Also if you are using global variables those will need to be reset to their original state

Thanks for the help guys. After changing to composer everything worked how I expected it to. Been a while since using corona and didn’t know about the change :smiley:

@Tom Hanson, its hard to help without seeing the complete code. Putting only part of it and ask the community to give you hint,  is a tough call. This being said, and based on your observation I would verify that you do not call twice Runtime:addEventListener( “enterFrame”, main) before ensuring you always remove first the event listener…

Also, why do you still use the obsolete Storyboard ? You should move to Composer.

Thanks for the reply. Yeah in my search I found that Storyboard was obsolete so I am in the process of converting the whole thing. And thanks for the suggestion. I will check to see if that is happening. Thank you

Also if you are using global variables those will need to be reset to their original state

Thanks for the help guys. After changing to composer everything worked how I expected it to. Been a while since using corona and didn’t know about the change :smiley: