probably silly question

I'm brand new to programming, sorry if this is lame :) The idea of the code below is to hide the donkey by clicking its tail, then, if it is hidden, show it - also by clicking its tail. I can get click to hide working, but then cannot click to show. I wonder if someone can lend a hand, I would sure appreciate help.

local function hidedonk (event)
donkey.isVisible = false
end

local function showdonk (event)
donkey.isVisible = true
end

if donkey.isVisible == true then
tail:addEventListener ("touch", hidedonk)

elseif donkey.isVisible == false then
tail:addEventListener ("touch", showdonk)
end

how about this?

1
2
3
4
5
local function toggleDonkeyVisibility (event)
   donkey.isVisible = not donkey.isVisible
end
 
tail:addEventListener ("touch", toggleDonkeyVisibility)

Hi Raúl, thanks. That hides the donkey on mouse down but on release it reappears. I'm sure there is a way to rectify that issue. I wonder what I am doing wrong in my original code, if anyone can tell me. It would help me learn what the heck I am doing to figure out how I am screwing that up.

Thanks again extremely.

views:1674 update:2011/10/19 8:59:29
corona forums © 2003-2011