Where to place object:removeSelf() ?

I’m trying to reset my app and I’ve been reading on the Object.removeSelf and object = nil functions but I can’t find clear documentation on where in the code they should be placed.

I’m basically trying to reset the state of my checkBoxes (and in a second app reset the entire game, or at least the score, score = 0 didn’t do it).

I followed the documentation found on the Corona website but it’s not clear where to place the lines. If you place it right after the creation of the checkBoxes they don’t even appear in the game. 

I tried to attach the code on my scene change function but I get errors.

I hate having to reopen the app every time just to reset it.

Any help would be appreciated. 

local function changeScene4() local options = { effect = "crossFade", time = 800 } radioGroup:removeSelf() radioGroup = nil composer.gotoScene( "scene4", options ) end

Scene:create() is where you create your objects.

Scene:show() is where you configure state for those objects.

In your case, create the checkboxes in create() and then set starting values in show().

I already have the objects created (I just didn’t show all my code)

I’m just trying to remove the value, or reset my checkboxes once I leave my scene (So when the use starts over the checkboxes are reset to “false”).

Everything I’ve read tells me to simply use the “removeSelf” command, but never show were in the code to place the line.

All the information I find online is for StoryBoards and not Composer.

There has to be a way to reset values (or the whole game itself)?

removeSelf() is to remove the object.  First create an object to display players score

local myScoreBox = display.newText("0", 100, 200, native.systemFont, 12) local myScore = 0

then to update it

myScore = myScore + 10 myScoreBox.text = myScore

to reset it

myScore = 0 myScoreBox.text = myScore

I found a method that involves creating a “reset.lua” scene, but for each scene.

Here is the code I found to create the “reset.lua”  file, incase someone else has the same issues. Just have your rest button directed to this file.

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) print( "((create scene RestartDummy's view))" ) local params = event.params -- print(params.myData) end --function scene:create( event ) function scene:show( event ) local phase = event.phase if "did" == phase then print( "((show scene RestartDummy's view))" ) composer.removeScene( "scene2") composer.removeScene( "scene3") composer.gotoScene( "scene1", "fade", 0 ) end end function scene:hide( event ) local phase = event.phase if "will" == phase then print( "((hiding scene RestartDummy's view))" ) end end function scene:destroy( event ) print( "((destroying scene RestartDummy's view))" ) end -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

Scene:create() is where you create your objects.

Scene:show() is where you configure state for those objects.

In your case, create the checkboxes in create() and then set starting values in show().

I already have the objects created (I just didn’t show all my code)

I’m just trying to remove the value, or reset my checkboxes once I leave my scene (So when the use starts over the checkboxes are reset to “false”).

Everything I’ve read tells me to simply use the “removeSelf” command, but never show were in the code to place the line.

All the information I find online is for StoryBoards and not Composer.

There has to be a way to reset values (or the whole game itself)?

removeSelf() is to remove the object.  First create an object to display players score

local myScoreBox = display.newText("0", 100, 200, native.systemFont, 12) local myScore = 0

then to update it

myScore = myScore + 10 myScoreBox.text = myScore

to reset it

myScore = 0 myScoreBox.text = myScore

I found a method that involves creating a “reset.lua” scene, but for each scene.

Here is the code I found to create the “reset.lua”  file, incase someone else has the same issues. Just have your rest button directed to this file.

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) print( "((create scene RestartDummy's view))" ) local params = event.params -- print(params.myData) end --function scene:create( event ) function scene:show( event ) local phase = event.phase if "did" == phase then print( "((show scene RestartDummy's view))" ) composer.removeScene( "scene2") composer.removeScene( "scene3") composer.gotoScene( "scene1", "fade", 0 ) end end function scene:hide( event ) local phase = event.phase if "will" == phase then print( "((hiding scene RestartDummy's view))" ) end end function scene:destroy( event ) print( "((destroying scene RestartDummy's view))" ) end -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene