Double Press

Hi thre. Im trying to implement this: When i press button it displays object, when i press it again same button the object disappear.
Here is the code i have so far

[code]
– settings function
local function optionsPressed(b)
overlayGroup = display.newGroup()
game.playEventSound(game.soundPressed)
settingsOverLay = display.newImageRect(“mainscene/settingsoverlay.png”, 57, 131)
settingsOverLay.x = 50
settingsOverLay.y = 207
–transition.to(settingsOverLay,{time = 100, x = 50 , y = 207 })
overlayGroup:insert(settingsOverLay)

— Craetae buttons here
soundButton=button:create(overlayGroup,1,{x=50,y=220,w=45,h=45,handler=soundPressed},“buttons/soundicon.png”)
if game.sound == false then soundButton.image=“buttons/soundiconover.png” end

– Musik Icon button
musicButton=button:create(overlayGroup,1,{x=50,y=170,w=45,h=45,handler=musikPressed},“buttons/musicicon.png”)
if game.music == false then musicButton.image=“buttons/musiciconover.png” end

– When i press same button i want all of the above to be gone.

end
– Settings button
button:create(group,1,{x=50,y=280,w=65,h=65,handler=optionsPressed},“buttons/settingsicon.png”)

[/code] [import]uid: 11559 topic_id: 20505 reply_id: 320505[/import]

Could you have this?

[code]
– settings function
local overlayGroup

local function optionsPressed(b)
if overlayGroup then
display.remove(overlayGroup)
else
overlayGroup = display.newGroup()

game.playEventSound(game.soundPressed)
settingsOverLay = display.newImageRect(“mainscene/settingsoverlay.png”, 57, 131)
settingsOverLay.x = 50
settingsOverLay.y = 207
–transition.to(settingsOverLay,{time = 100, x = 50 , y = 207 })
overlayGroup:insert(settingsOverLay)

— Craetae buttons here
soundButton=button:create(overlayGroup,1,{x=50,y=220,w=45,h=45,handler=soundPressed},“buttons/soundicon.png”)
if game.sound == false then soundButton.image=“buttons/soundiconover.png” end

– Musik Icon button
musicButton=button:create(overlayGroup,1,{x=50,y=170,w=45,h=45,handler=musikPressed},“buttons/musicicon.png”)
if game.music == false then musicButton.image=“buttons/musiciconover.png” end

end
end

– Settings button
button:create(group,1,{x=50,y=280,w=65,h=65,handler=optionsPressed},“buttons/settingsicon.png”)
[/code] [import]uid: 94868 topic_id: 20505 reply_id: 80422[/import]

Thanks for the help. It works once then gives me this error

“Runtime error
bad argument #-1 to ‘?’ (Proxy expected, got nil)
stack traceback:
[C]: ?
[C]: in function ‘?’
?: in function ‘removeSelf’
?: in function ‘remove’
…/Ayena LLC/Corona/Impossible Test Game/mainscene.lua:66: in function ‘buttonEventHandler’
…nts/Ayena LLC/Corona/Impossible Test Game/button.lua:113: in function <…nts llc test game>
?: in function <?:215>

” [import]uid: 11559 topic_id: 20505 reply_id: 80436[/import] </…nts>

whoops. try adding this on the line after “display.remove(overlayGroup)”

overlayGroup = nil

[import]uid: 94868 topic_id: 20505 reply_id: 80526[/import]

Thanks a lot man. [import]uid: 11559 topic_id: 20505 reply_id: 80662[/import]