going to the beginning of a scene?

Ok, after some more testing just now of my scene (originally discussed http://forums.coronalabs.com/topic/49515-ui-element-name-display/#entry256194 ) I’ve come to the conclusion that i beleive scenes opperate like a tape deck would, in that when you leave a scene, you’re ejecting a tape, but not re-winding it, and THAT is what I essentially need to do, go back to the beginning of a scene (it’s a level selection menu), and not to the end of the scene where it was (which is popping up a now blank window that has an invisible play button). Currently, I’m deleting the levelSelect scene when loading the actual level scene, and  at the end of a game (where I’d be going back to the levelScreen, I’m currently getting an error

?:0: attempt to index field 'contentBounds' (a nil value)

The simplest thing to do is before you call:

composer.gotoScene(“somescenename”)

call the removeScene() function… Lets say the scene you want to goto is called “menu”:

composer.removeScene(“menu”)

composer.gotoScene(“menu”, otherParameters)

Rob

I’ve done that, (I actually delete in the function/button click that takes me to the play scene which I don’t think should make a difference). it seems like this function is the one referencing contentBounds:

function Map:restrictBounds() --restricts the view to the content edges local group = self.group local disp = self.disp local bounds = group.contentBounds local xMin,yMin = disp:localToContent(bounds.xMin, bounds.yMin) local xMax,yMax = disp:localToContent(bounds.xMax, bounds.yMax) local dW, dH = display.contentWidth, display.contentHeight if (xMin \> 0) then group.x = 0 elseif (xMax \< dW) then group.x = dW-group.width end if (yMin \> 0) then group.y = group.height elseif (yMax \< dH) then group.y = dH end end

But I’m not sure why it’s not being re-created when the scene is re-started.

I’m truly confused about what your issue is.

What version of Corona SDK are you using?

Is your app Composer based or Storyboard based?

What is the exact problem you are having (this is the first time I’ve  heard about content bounds).

It will be helpful to watch this video.  http://coronalabs.com/blog/2013/08/20/tutorial-reloading-storyboard-scenes/

While it’s about Storyboard, the concepts are the same.  This will help you understand why things don’t appear to reset in scene changes.

Rob

Sorry for being confusing, i tend to do that to myself a lot :smiley:

The issue is that when it goes to switch back to the level map (the game ends scene ends, a button is pressed to take you back to level select) it crashes with that error.

the function i copied is from what I believe is a stock map.lua file.

Thank you for the link, I’ll watch the video, and report back if i have any more problems.

Is there more information in your console log?  There should be a stack trace there that should provide you more information.  If you  don’t know how to view your console log, please read:  http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Rob

There in fact is, but I think that video perfectly describes the issues I/the team is having with it. I came to the conclusion that the scene was going back to the point where it left off when I realized that the opaue window I was previously referring to was the same window that starts the map level in the first place. So I think taking the right course of action to actually reload a scene will hopefully solve our problems.

Thanks again!

Edit to add: the full trace is as follows:

Runtime error ?:0: attempt to index field 'contentBounds' (a nil value) stack traceback: ?: in function '\_saveSceneAndHide' ?: in function 'gotoScene' h:\sticky-fingers-adventure\trunk\code base\swapgame.lua:432: in function \<h:\sticky-fingers-adventure\trunk\code base\swapgame.lua:427\> ?: in function \<?:218\>[Finished in 63.3s]

The simplest thing to do is before you call:

composer.gotoScene(“somescenename”)

call the removeScene() function… Lets say the scene you want to goto is called “menu”:

composer.removeScene(“menu”)

composer.gotoScene(“menu”, otherParameters)

Rob

I’ve done that, (I actually delete in the function/button click that takes me to the play scene which I don’t think should make a difference). it seems like this function is the one referencing contentBounds:

function Map:restrictBounds() --restricts the view to the content edges local group = self.group local disp = self.disp local bounds = group.contentBounds local xMin,yMin = disp:localToContent(bounds.xMin, bounds.yMin) local xMax,yMax = disp:localToContent(bounds.xMax, bounds.yMax) local dW, dH = display.contentWidth, display.contentHeight if (xMin \> 0) then group.x = 0 elseif (xMax \< dW) then group.x = dW-group.width end if (yMin \> 0) then group.y = group.height elseif (yMax \< dH) then group.y = dH end end

But I’m not sure why it’s not being re-created when the scene is re-started.

I’m truly confused about what your issue is.

What version of Corona SDK are you using?

Is your app Composer based or Storyboard based?

What is the exact problem you are having (this is the first time I’ve  heard about content bounds).

It will be helpful to watch this video.  http://coronalabs.com/blog/2013/08/20/tutorial-reloading-storyboard-scenes/

While it’s about Storyboard, the concepts are the same.  This will help you understand why things don’t appear to reset in scene changes.

Rob

Sorry for being confusing, i tend to do that to myself a lot :smiley:

The issue is that when it goes to switch back to the level map (the game ends scene ends, a button is pressed to take you back to level select) it crashes with that error.

the function i copied is from what I believe is a stock map.lua file.

Thank you for the link, I’ll watch the video, and report back if i have any more problems.

Is there more information in your console log?  There should be a stack trace there that should provide you more information.  If you  don’t know how to view your console log, please read:  http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Rob

There in fact is, but I think that video perfectly describes the issues I/the team is having with it. I came to the conclusion that the scene was going back to the point where it left off when I realized that the opaue window I was previously referring to was the same window that starts the map level in the first place. So I think taking the right course of action to actually reload a scene will hopefully solve our problems.

Thanks again!

Edit to add: the full trace is as follows:

Runtime error ?:0: attempt to index field 'contentBounds' (a nil value) stack traceback: ?: in function '\_saveSceneAndHide' ?: in function 'gotoScene' h:\sticky-fingers-adventure\trunk\code base\swapgame.lua:432: in function \<h:\sticky-fingers-adventure\trunk\code base\swapgame.lua:427\> ?: in function \<?:218\>[Finished in 63.3s]