Get current storyboard scene

OK, so this is probably obvious to a lot of folks, as I’ve read posts in which people mention getting the current scene using storyboard. However, I’ve tried a number of things to get the current scene and keep falling flat. I have a tabBar on the main.lua page that will change the scene using a custom scene attribute I created when creating the tabBar buttons. Clicking on a button runs a storyboard.gotoScene on the scene property of the targeted button.

storyBoard.getPrevious() will return the previous scene just fine, but how in the world do I get the current scene?

I’ve tried

  • storyboard.getScene(self)

  • storyboard.getScene(self.view)

  • storyboard.view

  • storyboard.scene

  • storyboard[1]

  • …etc.

[import]uid: 19999 topic_id: 21494 reply_id: 321494[/import]

I would like to know that as well… anyone? [import]uid: 114363 topic_id: 21494 reply_id: 85077[/import]

Use storyboard.getScene(), but you must pass a string name as the argument (string).

Here is the reference page for that API:
http://developer.anscamobile.com/reference/index/storyboardgetscene [import]uid: 52430 topic_id: 21494 reply_id: 85090[/import]

Doesn’t that get the scene object of the argument you passed?
What if you want to know what the current scene is?

For my specific reason: I have a global function that handles the android back button keypress, but I want to display a message when the user pressed the back button only when in 1 specific scene.

[import]uid: 114363 topic_id: 21494 reply_id: 85098[/import]

Ok… so I would assume there is no way to get the current scene you are in, so I have a workaround…

I created a global variable (CURRENT_SCENE) and in each scene’s enterScene function, I assign the name of the scene:

CURRENT_SCENE = “scene_whatever”

Only way I can figure at this time. [import]uid: 114363 topic_id: 21494 reply_id: 87339[/import]

@schizoid2k, that’s a work-around and I can certainly use it. However, it seems odd that I can access the previous scene and not the current scene. The ability to access a previous scene indicates, to me, that scene info is being stored in a stack somewhere. Jonathan, why wouldn’t we want to be able to access that info as well?

The clearest and probably most-used example I can think of is using a universal button handler to switch scenes, and first checking if you are already on that scene so that the button doesn’t reload if the current scene is the same as where I want to direct the user to. [import]uid: 19999 topic_id: 21494 reply_id: 87354[/import]

getPrevious() gets you the scene name of the previous scene which of course you may need to get back to where you were.

But given the scene name is the name of the lua file you’re editing, you know what file you’re editing so there is no practical reason to get the current scene name.

I know you’re saying, what if I have level1.lua, level2.lua etc. But if you’re writing code for level2.lua it’s just as easy to hard code the name as it is to code up some automated way to fetch the name.

If you really think you still need it, grab the print_r function from the community code (or any other table printer) and print the storyboard table and see if there is by chance a hidden value in there.

If there is not then you can either hardcode your scene name at the top of your file after you require(“storyboard”):

local storyboard = require("storyboard")  
storyboard.name = "myname".  

or if you want to do it in the model you came from:

  
...  
storyboard.name = "myname"  
storyboard.gotoScene("myname")  
  
...  
  
-- then in myname.lua....  
  
print(storyboard.name)  

[import]uid: 19626 topic_id: 21494 reply_id: 87357[/import]