Weird code behavior.. Please help

The idea of removing them in the scene:show() function somewhat confuses me.

Can I remove them in the scene:hide() function  :huh: ?

Yes, I believe you can…l I have never tried it but i’m pretty sure you can… 

Mate you are a life saver. :)  Thank you for assisting me 

It didn’t work man :frowning:

I wrote the function in the scene:hide() “did” phase but It didn’t work :-(((

my guess is it didn’t work because scope is not seeing it.

–SonicX278

I read about scope and solved the issue about the score text not updating properly :slight_smile:

However I’m still stuggling with the invisible platforms :frowning:

And something confuses me, is it better to declare display objects in the scene:create() or scene:show() function ? Same question about functions and event listeners.

And how could I remove objects and their listeners if they are local variables not available in all code functions ?

I’m sorry if my questions are obvious, but I’m trying so hard to figure out a solution !

Hello, I’m out of state so in on my phone so here is the best I can answer you with.

You have to put your display objects into scene show after the did phase and add then to the self.view(aka sceneGroup). Try adding hybrid mode to the physics and see if objects are being randomly added.

To remove an object you do

display.remove(objectName)

To remove a listener you do

Runtime/orObject:removeEventListener( “listenerType”, function )

–SonicX278

So should I remove the objects/listeners in which scene event ?

In the did phase of scene show

So you make a function and then call it when you are changing scenes …

Local function removeThings()
Display.remove
Listener remove
End

And then you call it with

removeThings()

Good luck!

so for example: if I press the exit button an exit function is executed and within this function, removeThings() is called ?

Exactly! But make sure scope sees the function being called… If it doesn’t then make it global… But try to stay away from globals…

IT FINALLY WORKED !!! I had to declare the display objects as global variables and made a function removing all display objects and only the Runtime event listener. Thank you very much !! 

This issue has been solved. However, there is not a “one-post solution” but rather a serie of questions and answers.