How do I go back to the scene I came from in composer?

So basically I am trying to make a choose your own adventure game, and my set up so far is main.lua -> menu.lua -> play.lua -> exploring
-> waiting -> waiting longer

And I have a menu button in every scene to go back to the menu now what I want to know is if I go back to the menu scene in waiting longer how do I push play to take me back to waiting longer not go through with the program like normal? Any help is greatly apreciated

This should do (;
http://docs.coronalabs.com/api/library/composer/getSceneName.html

Alternatively, you can save the name of the scene within the hide event to a variable, and in menuScene use an if/else statement. If the variable contains a scene name, load that scene, else, load the first scene of the game.

Thanks man, sorry but I’m really new to coding so could you give me a bit of an example as to how I would do that thanks for your help!

Sure. Here’s an example to use the getSceneName function to get the previous loaded scene:
 

local prevScene = composer.getSceneName( "previous" ) composer.gotoScene( prevScene )

And here’s a bit of elaboration on what I was talking about before, saving the scene name in a variable and utilize it again in the menu:
 

--in your game lua file, within the hide function of Composer \_G.myPreviousGameSceneName = "the name of the scene you'd like to keep"; --within the menu lua file, in the button touch function, or in general where the code to go to the game scene goes. Your current composer.gotoScene call would be substituted by what's below here. if \_G.myPreviousGameSceneName then composer.gotoScene(\_G.myPreviousGameSceneName); \_G.myPreviousGameSceneName = nil; else composer.gotoScene("the name of the scene you first load normally from the menu"); end

Another option might be to create a secondary menu as an overlay. Depends on what you envision your users doing.

T.

thanks so much for your help! the only thing that I cant figure out is. It works fine if I go to and from the exploring scene, but I get an error like I never went to another scene for any other scene. do you have any idea of what could be causing this they are all written exactly the same except for the text that I’m displaying.

I would need to take a better look at the code, and I’m not sure I got exactly what the problem is.
Basically, if you go to menu->scene1->scene2->menu and press play, it goes to scene1 instead of scene2?

Sorry I couldn’t get back to you earlier I’ve been busy but I figured it out so I made a pause menu which takes you back to the menu or resumes the game the menu works perfectly fine but when I use the resume button I always go back to the scene I first used it on for example I paused and resumed the game in file1 I then pause the game in file 2 and when I push resume I go back to file 1 any idea how to fix this I have it set up so when I push resume I goto the previous scene thanks for all your help

Please keep in mind, Composer (and previously Storyboard) does not support a history.  You cannot use it to back out of multiple scenes.  For example lets say you have SceneA go to SceneB which then goes to SceneC.  If you call

local lastScene = composer.getSceneName( “previous” )

it will return “SceneB” and then you call

composer.gotoScene(lastScene)

the next time you call composer.getSceneName(“previous”) you end up with “SceneC” since “SceneC” is the previous scene.  Call it again you get SceneB, etc. 

Rob

This should do (;
http://docs.coronalabs.com/api/library/composer/getSceneName.html

Alternatively, you can save the name of the scene within the hide event to a variable, and in menuScene use an if/else statement. If the variable contains a scene name, load that scene, else, load the first scene of the game.

Thanks man, sorry but I’m really new to coding so could you give me a bit of an example as to how I would do that thanks for your help!

Sure. Here’s an example to use the getSceneName function to get the previous loaded scene:
 

local prevScene = composer.getSceneName( "previous" ) composer.gotoScene( prevScene )

And here’s a bit of elaboration on what I was talking about before, saving the scene name in a variable and utilize it again in the menu:
 

--in your game lua file, within the hide function of Composer \_G.myPreviousGameSceneName = "the name of the scene you'd like to keep"; --within the menu lua file, in the button touch function, or in general where the code to go to the game scene goes. Your current composer.gotoScene call would be substituted by what's below here. if \_G.myPreviousGameSceneName then composer.gotoScene(\_G.myPreviousGameSceneName); \_G.myPreviousGameSceneName = nil; else composer.gotoScene("the name of the scene you first load normally from the menu"); end

Another option might be to create a secondary menu as an overlay. Depends on what you envision your users doing.

T.

thanks so much for your help! the only thing that I cant figure out is. It works fine if I go to and from the exploring scene, but I get an error like I never went to another scene for any other scene. do you have any idea of what could be causing this they are all written exactly the same except for the text that I’m displaying.

I would need to take a better look at the code, and I’m not sure I got exactly what the problem is.
Basically, if you go to menu->scene1->scene2->menu and press play, it goes to scene1 instead of scene2?

Sorry I couldn’t get back to you earlier I’ve been busy but I figured it out so I made a pause menu which takes you back to the menu or resumes the game the menu works perfectly fine but when I use the resume button I always go back to the scene I first used it on for example I paused and resumed the game in file1 I then pause the game in file 2 and when I push resume I go back to file 1 any idea how to fix this I have it set up so when I push resume I goto the previous scene thanks for all your help

Please keep in mind, Composer (and previously Storyboard) does not support a history.  You cannot use it to back out of multiple scenes.  For example lets say you have SceneA go to SceneB which then goes to SceneC.  If you call

local lastScene = composer.getSceneName( “previous” )

it will return “SceneB” and then you call

composer.gotoScene(lastScene)

the next time you call composer.getSceneName(“previous”) you end up with “SceneC” since “SceneC” is the previous scene.  Call it again you get SceneB, etc. 

Rob