Back Button

Hello! I’m using Storyboard and attempting to create a back button that returns the user to the screen they were previously at. The back button is currently on a tabBar, so I want it to “figure out” what the previous screen was and then go to that screen when the back button is pressed.
Can anyone share their knowledge?

Thanks!
Nathan [import]uid: 39302 topic_id: 35563 reply_id: 335563[/import]

Hi,
I’m just an newbie so take advice with that in mind.

I would think using a global variable to identify the previous storyboard scene could be used somehow.

By putting one line kind of like - previousScene = “scene.lua”
inside the change.scene function or what ever function you use to go forward in the game

function changeScene(e)
if(e.phase == “ended”) then
previousScene = “scene.lua”
storyboard.gotoScene(e.target.scene)
end
end

then on your back function
use that variable somehow.

I’ve never tried it - i tend to use menu buttons - ie push it and it goes back to the menu screen
I started out with a number of scenes but in order to make the code “prep” ready for any problems - figured out how to make some KEY variables global then slam in some if’s - elseif’s to take the code down to a - main/Menu/How2/Game kind of situation, where Game does all the heavy lifting under multiple situations.
T. [import]uid: 199068 topic_id: 35563 reply_id: 141348[/import]

See: http://docs.coronalabs.com/api/library/storyboard/getPrevious.html

This will return you the previous scene name that you can then pass to gotoScene() [import]uid: 199310 topic_id: 35563 reply_id: 141363[/import]

Thanks for the replies.

The following is what worked for me.
 

local previousScene = storyboard.getPrevious() storyboard.gotoScene( previousScene )

Thanks for giving me your time. I appreciate it. [import]uid: 39302 topic_id: 35563 reply_id: 141378[/import]

Hi,
I’m just an newbie so take advice with that in mind.

I would think using a global variable to identify the previous storyboard scene could be used somehow.

By putting one line kind of like - previousScene = “scene.lua”
inside the change.scene function or what ever function you use to go forward in the game

function changeScene(e)
if(e.phase == “ended”) then
previousScene = “scene.lua”
storyboard.gotoScene(e.target.scene)
end
end

then on your back function
use that variable somehow.

I’ve never tried it - i tend to use menu buttons - ie push it and it goes back to the menu screen
I started out with a number of scenes but in order to make the code “prep” ready for any problems - figured out how to make some KEY variables global then slam in some if’s - elseif’s to take the code down to a - main/Menu/How2/Game kind of situation, where Game does all the heavy lifting under multiple situations.
T. [import]uid: 199068 topic_id: 35563 reply_id: 141348[/import]

See: http://docs.coronalabs.com/api/library/storyboard/getPrevious.html

This will return you the previous scene name that you can then pass to gotoScene() [import]uid: 199310 topic_id: 35563 reply_id: 141363[/import]

Thanks for the replies.

The following is what worked for me.
 

local previousScene = storyboard.getPrevious() storyboard.gotoScene( previousScene )

Thanks for giving me your time. I appreciate it. [import]uid: 39302 topic_id: 35563 reply_id: 141378[/import]