Tap to display then tap again to hide..?

So I am trying to create a button that will allow me to tap to show an inventory panel, then tap the button again to hide the inventory panel.

I have written a function that works for displaying the inventory in the correct location, can someone give me a tip on how to allow it to hide the panel if I press the button again. I am assuming i need to do some kind of boolean. Can someone give me an example to set me on the right path?

Thanks,

Blade…

[code]local function inventoryButtont ( event )
if event.phase == “release” and inventoryBox == closed then

audio.play(puckHitPaddle)
local inventoryBucket = display.newImage(“images/inventoryBucket.png” , 100, 700)
inventoryBox = open
end

[code]
end
[import]uid: 64906 topic_id: 10672 reply_id: 310672[/import]

Try this. Untested, but it should set you in the right direction.

[code]
local button = display.newRect(0, 0, 100, 100)
local panelOpen = false – set the initial state of the panel (closed by default)
local inventoryBucket = display.newImage(“images/inventoryBucket.png” , 100, 700)
inventoryBucket.isVisible = false --hide the .png by default

local function ButtonTouch(event)
if event.phase == “ended” then
if panelOpen == false then
panelOpen = true
audio.play(puckHitPaddle)
inventoryBucket.isVisible = true --show the panel
else
panelOpen = false
audio.play(puckHitPaddle)
inventoryBucket.isVisible = false --hide the panel
end
end

button:addEventListener( “touch”, ButtonTouch )
[/code] [import]uid: 48658 topic_id: 10672 reply_id: 38738[/import]

Thanks, that totally helped.

I am guessing it probably makes sense to make this inventory global rather than just for a particular screen. Now need to figure that out…

anyway here is my solution…

[code]
local function inv01t ( event )
if event.phase == “release” then
if panelOpen == false then

panelOpen = true
audio.play(beepSound)
inventoryBucket.isVisible = true – show bucket

else
panelOpen = false
audio.play(beepSound)
inventoryBucket.isVisible = false

end

end
end

[code] [import]uid: 64906 topic_id: 10672 reply_id: 38739[/import]