When games ends: go to scene

UPDATE: I HAVE NOW REMOVED MY PROJECT FROM MY DOWNLOAD PAGE. IF YOU WOULD LIKE TO HELP ME BY USING MY CODE PLEASE CONTACT ME ON RYAN@GROMFROG.COM.
I have been Corona for around 3 months and have already created my first game ready for launch. But I have hit a brick wall. I have been using tutorials from around the net to help me with this game and some of the code is from a Mobile Tuts+. The game i am working on is a falling game like “Fall down” this is one game in a collection of games I am working on. Now to my issue.

I am using physics, storyboard api.

I have got the main.lua file file directing you to the fall.lua which is the game. then i have got the game working how i want it but at the end of the file I have the following code:

-- Check for Game Over   
  
 if(lives \< 0) then  
 showAlert()  
 end  
  
 -- Levels   
  
 if(score \> 500 and score \< 502) then  
 moveSpeed = 3  
 end  
end  
  
function collisionHandler(e)  
 -- Grab Lives  
  
 if(e.other.name == 'live') then  
 display.remove(e.other)  
 e.other = nil  
 lives = lives + 1  
 livesTF.text = 'x' .. lives  
 end  
  
 -- Bad Blocks  
  
 if(e.other.name == 'bad') then  
 lives = lives - 1  
 livesTF.text = 'x' .. lives  
 end  
end  
  
function showAlert()  
 gameListeners('rmv')  
 local alert = display.newImage('alertBg.png', 70, 190)  
  
 alertScore = display.newText(scoreTF.text .. '!', 134, 240, native.systemFontBold, 30)  
 livesTF.text = ''  
  
 transition.from(alert, {time = 200, xScale = 0.8})  
 end  
  

I want to not use the function showAlert() and in it’s place direct the user when the lives hit less than 0 to a file called score.lua.
I want to do this because I want to have more space to show score, where the user is on the leader board, and allow the user to share to facebook and twitter.

Is there a way to replace the function showAlert () with a piece of code to send the user to the score.lua folder. I would like to use the storyboard api and I think I have got everything right as it is working.

If you would like to see my code/project please leave a reply and I will post it on my site for download.

I really need some help.

Thanks

Ryan [import]uid: 111430 topic_id: 23185 reply_id: 323185[/import]

In CoronaSDK > SampleCode > Interface > Storyboard there is a sample project showing how to switch between scenes.

If you open scene4.lua in that folder you will see how scene change works with Storyboard.

Let me know if that helps :slight_smile:

(If you are comfortable posting your project as you said I’m happy to take a look at it if I can find a little free time tonight/tomorrow as well.)

Peach :slight_smile: [import]uid: 52491 topic_id: 23185 reply_id: 92725[/import]

Hi peach I will have alook at the example later once I get back from my walk.

Thanks
Ryan [import]uid: 111430 topic_id: 23185 reply_id: 92730[/import]

Hi Peach, here is the link to my project. The download will be removed in 6 hours.

I understand what I would need to use but I cannot get the image to to show at the end of the game like i currently have (i will be changing the image) and then let the user tap to continue and go to the other file.

Would really like your help.

http://gromfrog.com/downloads/Crate%20Fall%20Ducky%20Run.zip

Ryan. [import]uid: 111430 topic_id: 23185 reply_id: 92743[/import]

You have a couple of choices.

You can add a button to your alert screen that the player taps to move to the end game screen, or you can use a timer set to 5 seconds or so that will do your storyboard.gotoScene() call to load your game over screen.

[import]uid: 19626 topic_id: 23185 reply_id: 92749[/import]

Hey thanks will have a look at this method [import]uid: 111430 topic_id: 23185 reply_id: 92750[/import]

I have tried using storyboard.gotoScene()with alsorts of methods and every time I try it, it seems to bring back loads of errors and they come up so fast I cannot read them [import]uid: 111430 topic_id: 23185 reply_id: 92768[/import]

You need to have your scene created in a certain way in order to use it with storyboard.

it must have the following as a minimum

require( "storyboard" )  
local scene = storyboard.newScene()  
  
function scene:createScene( event )  
end  
  
function scene:enterScene( event )  
end  
  
function scene:exitScene( event )  
end  
  
function scene:destroyScene( event )  
end  
  
scene:addEventListener("createScene", scene )  
scene:addEventListener("enterScene", scene )  
scene:addEventListener("exitScene", scene )  
scene:addEventListener("destroyScene", scene )  
  
return scene  
  

Your setup code for the scene should go into the createScene function.

Your initialisation code should go into the enterScene as this is called every time a scene is entered but create is only called if the scene was previously destroyed (unloaded from memory).
[import]uid: 82631 topic_id: 23185 reply_id: 92771[/import]

I have had an idea that when the alert image loads it goes to the gameover lua file using storyboard. But i cannot seem to work out or find some code for this. Any help?

More info here http://developer.anscamobile.com/forum/2012/03/12/when-image-loads-gotoscene [import]uid: 111430 topic_id: 23185 reply_id: 92784[/import]