Troubles with function object:tap ( event )

Long story short I am new here and this is what I have and I dont understand where I am making my mistake. What I want is for the “cover” (Page0.jpg 768x1024) to be tapped then “topMenu” (tapMenuBtn.png 768x150) to display (toggled). Then If I tap “topMenu” to have “topMenuDD” (tapMenuBtnDD.png 650x400) display.

The “topMenu” displays but no matter where I tap on the screen, “topMenu” goes away and “topMenuDD” never comes up. I figure it has something to do with not being able to tap “topMenu” but I dont know for sure.

PLZ help. Lemme know what I can do to make this work.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
local cover = display.newImage (“Page0.jpg”)
function cover:tap ( event )
if topMenu == nil then
topMenu = display.newImage (“tapMenuBtn.png”,0,0)
else
topMenu:removeSelf()
topMenu=nil
end
end

cover:addEventListener (“tap”, cover)
function topMenu:tap ( event )
topMenuDD = display.newImage (“tapMenuBtnDD.png”,0,150)
end
topMenu:addEventListener (“tap”, topMenu)
[import]uid: 112297 topic_id: 19592 reply_id: 319592[/import]

Hi there,

I just screen through your code. I think it might be your touch event overlapping each other? Try add “return true” before the “end” of both touch event functions, not sure it might help though. And you might want to set your function as a local function?

local function topMenu:tap ( event )  
 topMenuDD = display.newImage ("tapMenuBtnDD.png",0,150)  
 return true  
end  

[import]uid: 12979 topic_id: 19592 reply_id: 75734[/import]

local function cover:tap ( event )
if topMenu == nil then
topMenu = display.newImage (“tapMenuBtn.png”,0,0)
else
topMenu:removeSelf()
topMenu=nil
return true
end
end
cover:addEventListener (“tap”, cover)

+++++++++++++++++++++++++++++++++
Gives me the following error:
Syntax error: c:\users\marshal\desktop\corona\learner project\main.lua:18: ‘(’ expected near ‘:’

Clearly I made a mistake on the syntax, but I cant find where I cant figure out where it is (Just started using Lua a few days ago) [import]uid: 112297 topic_id: 19592 reply_id: 75737[/import]

I see, I am not very sure about function syntax, but for me I named them like this:

local cover = display.newImage ("Page0.jpg")  
  
local function coverTap ( event )  
  
if topMenu == nil then  
topMenu = display.newImage ("tapMenuBtn.png",0,0)  
else  
topMenu:removeSelf()  
topMenu=nil  
end  
  
return true  
end  
  
cover:addEventListener ("tap", coverTap)  
  
local function topMenuTap ( event )  
  
topMenuDD = display.newImage ("tapMenuBtnDD.png",0,150)  
  
return true  
end  
  
topMenu:addEventListener ("tap", topMenuTap)  

If your event logic is correct, this should work as expected? [import]uid: 12979 topic_id: 19592 reply_id: 75743[/import]

I tried that, but now it makes both images appear when clicking on the background.
I am having a terrible time with this, its supposed to be for making an ebook, but its not working so hot.

I wanna make this work out, but I cant make “topMenu” selectable. [import]uid: 112297 topic_id: 19592 reply_id: 75749[/import]

Try setting the object’s alpha or object.isVisible. If the code you post is everything I don’t think the way you add listener to topMenu is correct:

[code]
–Display Objects Here

local cover = display.newImage (“Page0.jpg”)

local topMenu = display.newImage (“tapMenuBtn.png”,0,0)
topMenu.alpha = 1

local topMenuDD = display.newImage (“tapMenuBtnDD.png”,0,150)
topMenuDD.alpha = 0

–Functions

local function coverTap ( event )

if topMenu.alpha == 1 then
topMenu.alpha = 0
elseif topMenu.alpha == 0 then
topMenu.alpha = 1
end

end

cover:addEventListener (“tap”, coverTap)

local function topMenuTap ( event )

topMenuDD.alpha = 1

return true
end

topMenu:addEventListener (“tap”, topMenuTap)
[/code] [import]uid: 12979 topic_id: 19592 reply_id: 75765[/import]

Chang Kian Boon… Sir you are a Genius!!!

Can you post a tutorial that might be able to help me understand what I am doing here? I really like this, its exactly what I needed! [import]uid: 112297 topic_id: 19592 reply_id: 75893[/import]

So I have the code working better now… DEFINEATELY better than what I had before. But when I try and tap on “topMenu” it acts like I am clicking on both “topMenu” and “cover” at the same time.

[code]
–Display Objects Here

local cover = display.newImage (“Page0.jpg”)

local topMenu = display.newImage (“tapMenuBtn.png”,0,0)
topMenu.alpha = 0

local topMenuDD = display.newImage (“tapMenuBtnDD.png”,0,150)
topMenuDD.alpha = 0

–Functions

local function coverTap ( event )

if topMenu.alpha == 1 then
topMenu.alpha = 0
elseif topMenu.alpha == 0 then
topMenu.alpha = 1
end

end

cover:addEventListener (“tap”, coverTap)

local function topMenuTap ( event )

if topMenuDD.alpha == 1 then
topMenuDD.alpha = 0
elseif topMenuDD.alpha == 0 then
topMenuDD.alpha = 1
end

end

topMenu:addEventListener (“tap”, topMenuTap)
[/code] [import]uid: 112297 topic_id: 19592 reply_id: 75894[/import]

Marshall, I think you’ve dropped the “return true” from coverTap() and topMenuTap(). [import]uid: 22076 topic_id: 19592 reply_id: 75895[/import]

Wow that is amazing! all good now. I have it worked out 100% now. You guys are amazing [import]uid: 112297 topic_id: 19592 reply_id: 75921[/import]