The composer reload scene

Hi,

 I am having some troubles reloading my scene using composer.The first issue that ocurs is that my score doesn’t reset back to zero,alltough I have removed the current level.

  The second issue is that I get an error that says “Attempt to upvalue index…”.I get this error regarding some display objects that recived a nil value when the scene was removed.

  How can I fix those problems?

Thanks!

I would recommend watching the video and reading the tutorial here:  http://coronalabs.com/blog/2013/08/20/tutorial-reloading-storyboard-scenes/

It’s storyboard based, but the reloading concepts are the same.  It will help you understand when and where code gets executed and why things may not reset like you want.

Rob

greenFish.isVisible = false --Here's the line.

Hi Rob,

 I managed to reset the score,but I am still getting this annoying error.I am getting this error after my level is restarting.

Why?

Thanks!

error-2.jpg

All the information you need is in the error message.  At line 327 of levelOne.lua, you are trying to use a variable named greenFish that declared at somewhere at the top (upvalue, declared in a higher block) and it’s nil.  What you are trying to use it for, can’t take a nil value.  This is inside a function named listener.

Rob

Fixed it thanks.You we’re right.I just had to delete the line,where it has a nil value.But will this affect my game somehow,since the greenFish will not get a nil value once the level is removed,and upon reloading the scene will my game be laggy?

I can’t answer that.  You know your code.  What were you trying to do with that line of code?  How would you expect it’s removal to affect your program? 

On you know how removing that will change your program and if removing was the fix, or if you should have fixed why it was nil, or tested to see if it was nil and handle the condition accordingly.

Rob

I would recommend watching the video and reading the tutorial here:  http://coronalabs.com/blog/2013/08/20/tutorial-reloading-storyboard-scenes/

It’s storyboard based, but the reloading concepts are the same.  It will help you understand when and where code gets executed and why things may not reset like you want.

Rob

greenFish.isVisible = false --Here's the line.

Hi Rob,

 I managed to reset the score,but I am still getting this annoying error.I am getting this error after my level is restarting.

Why?

Thanks!

error-2.jpg

All the information you need is in the error message.  At line 327 of levelOne.lua, you are trying to use a variable named greenFish that declared at somewhere at the top (upvalue, declared in a higher block) and it’s nil.  What you are trying to use it for, can’t take a nil value.  This is inside a function named listener.

Rob

Fixed it thanks.You we’re right.I just had to delete the line,where it has a nil value.But will this affect my game somehow,since the greenFish will not get a nil value once the level is removed,and upon reloading the scene will my game be laggy?

I can’t answer that.  You know your code.  What were you trying to do with that line of code?  How would you expect it’s removal to affect your program? 

On you know how removing that will change your program and if removing was the fix, or if you should have fixed why it was nil, or tested to see if it was nil and handle the condition accordingly.

Rob