I am calling a function I have in a separate lua file that creates the user interface on screen. When you call the method a second time, if any of the UI items already exist it is supposed to remove it and replace it with a new UI. This works great for vector objects and text, but doesn’t appear to work for buttons. Running this code:
[lua]if (titleText:removeSelf()) then print (“title text removed”); end[/lua]
returns true just fine, but this code:
[lua]if (backButton:removeSelf()) then print(“back button removed”); end[/lua]
returns false. I’ve tried removing the button individually, as well as removing the display group it is in to no avail. I’ve tried instantiating the button via:
you cause the removeSelf() method of the backButton object to execute removing the object. But what you are also doing is checking the return value of that function to see if it is true or false. It’s very likely that for non-widget objects, there is an undocumented/accidental true/false being returned where as the button object does not return anything which will cause your if statement to evaluate as false.
Per the documentation, do not expect removeSelf() to return anything.
Fair enough, should have looked into it further. The problem I am running into is that I have a button press on the screen that is supposed to remove a bunch of objects, and replace them with another set of objects. I have found that using display.remove does indeed remove the objects from the screen, but my memory usage keeps increasing. Is there a way to show what is still in memory?
you cause the removeSelf() method of the backButton object to execute removing the object. But what you are also doing is checking the return value of that function to see if it is true or false. It’s very likely that for non-widget objects, there is an undocumented/accidental true/false being returned where as the button object does not return anything which will cause your if statement to evaluate as false.
Per the documentation, do not expect removeSelf() to return anything.
Fair enough, should have looked into it further. The problem I am running into is that I have a button press on the screen that is supposed to remove a bunch of objects, and replace them with another set of objects. I have found that using display.remove does indeed remove the objects from the screen, but my memory usage keeps increasing. Is there a way to show what is still in memory?
There is no “onEvent” event. Its a “touch” event. onEvent just passes the address of the function to the internal code which maintains this. You do not need to remove touch handlers on objects that will be destroyed. The only touch handlers that need removed are ones that are on the whole screen.
As for the crash, can you post the stack trace from your console window?
There is no “onEvent” event. Its a “touch” event. onEvent just passes the address of the function to the internal code which maintains this. You do not need to remove touch handlers on objects that will be destroyed. The only touch handlers that need removed are ones that are on the whole screen.
As for the crash, can you post the stack trace from your console window?