Error with storyboard and back button on device

No, you should only need to put this in main.lua once.  Anything more is going to lead to problems.  With all the print statements in there, what is being printed before you get the insert is nil error?  That should help you pin point where its happening.

Rob

After running the adb logcat again, it prints the following:
 
remove previous scene (before my create scene function)
create scene 5
will enter scene 5
enter scene 5
 
Then I push the back button and it prints the following:
 
back button code here
exit scene 5 (where my code is that removes listeners, etc.)
destroy scene 5
remove previous scene (before my create scene function in the menu screen)
create scene menu
will enter scene menu
enter scene menu
 
Then I try to go back into the same scene 5 and this prints (the same thing happens with other scenes with their respective print statements):
 
create scene 5
will enter scene 5
enter scene 5
Runtime error
?:0: attempt to call method ‘insert’ (a nil value)
stack traceback:
        ?: in function ‘_listener’
        ?: in function (?:141)
 
So it looks like my back button code is being called before my scene exits. In my back button code, there is the command storyboard.gotoScene( “scene_home” )  but in my scene 5 exit scene function, I am removing all of the listeners and such. Perhaps it is not able to remove the listeners before going to the home scene?

What does your enterScene() look like for scene 5?

Currently my enterScene() for scene 5 is empty with the exception of the print statement. I have the majority of my code in my createScene(). I have put print statements in every function I have as well as every place I am inserting something into a group and they are all running fine, too. Is there a way to call a function in scene 5 in my back button code in main.lua? If so, I could perform a check in the back button code to see if it is scene 5 and if it is scene 5 then I could run the menu button function in my scene 5? My menu button in scene 5 works every time. It only gives me this error when I press the back button.

Bump.

Can you post your code for Scene 5?

Hi Rob,

My code is fairly long so I am attaching the .lua file.

Any help is appreciated.