Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

It comes from the line of code
Started by letam.thucuc Nov 19 2019 08:07 PM

- - - - -
3 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

letam.thucuc

[GLOBAL: userInfoPane.html]
letam.thucuc
  • Observer

  • 2 posts
  • Corona SDK

-If I play the level once, everything works fine.

-If I restart the level multiple times but do NOT change the scene, everything works fine.

-If I change scene back and forth but do NOT restart the level, everything works fine.

-ONLY IF I change scenes AND THEN try to restart the level do I get "attempt to index local 'bounds' (a nil value)

 

It comes from the line of code that tries to call the function to get the bounds of the enemy box.

 

So without posting hundreds of lines of code.... is there something I can try to figure out what is going on? 

 

The object itself that I am passing to the function is not nil, it seems that only the contentBounds table is nil. 

 

But what I do not understand is why does this only happen in the one situation mentioned above?  

 

Is there something regarding contentBounds and switching composer scenes that I need to be aware of?

 

When I switch scenes I am composer.removeScene  on the level scene to make sure things get recreated properly when I go back to the scene.  Like I said, this works fine as long as I don't try to restart the level after changing scenes. 

 


[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 781 posts
  • Corona SDK

I fear this is too obscure to help with.  Can you shrink the project into a smaller form to demonstrate to the rest of us?  Sometimes doing this exercise reveals the error.

 

Also maybe you explain the problem more concisely.  I would like to help but I not quite sure what problem you are having or what exactly is failing.


  • pixec likes this

[TOPIC: post.html]
#3

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,177 posts
  • Corona SDK

As @sporkfin already said, you haven't shared enough. In order to debug something, it'd be useful to see some code. This sounds to me like the object falls out of scope as you move between scenes, but I can't know for certain.


  • pixec likes this

[TOPIC: post.html]
#4

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 934 posts
  • Corona SDK

I agree it sounds like a scope problem. My guess is: 

 

You have an object which is a global variable (whether intentionally or not). 

When you leave the scene the display object is removed as it is in a scene group which is removed, but the variable is not set to nil.

This means that this condition would be true:  

if myObject ~= nil then

but the object won't contain any of the display.* properties so checking for myObject.width would return nil.




[topic_controls]
[/topic_controls]