simple codes I bet you can help me with

So I have a button with a listener and I want it to only register and respond to the first click. Is there a code I can add that will count number of clicks so that I can make the listener invalid after a certain number of clicks?

Something else I tried is at the beginning I made object = true, and what I want to do is have the listener only to work when that statement is true.

For example (just to be clear on what I want)

If object = true then
button: addEventListener (“touch”, buttonHandler)
end

So that later on when I make object = false it won’t continue on to the event listener.

[import]uid: 35535 topic_id: 6500 reply_id: 306500[/import]

In the listener function remove the touch event listener from the button. That’ll be something like self:removeEventListener(“touch”, self) [import]uid: 12108 topic_id: 6500 reply_id: 22732[/import]

no unfortunately I wasn’t able to get it to work but here is a segment of my work so far if it helps you or anyone else that reads this.

red = true

function buttonHandler (e)
if(e.phase == “began”) then
audio.play (knock);
physics.setGravity (0, -3);
physics.addBody (button, “static”, {bounce= 0.5})
red = false

self:removeEventListener(“touch”, self)

end

–elseif (red = false) then
–audio.play (knock);

end

button: addEventListener (“touch”, buttonHandler)
[import]uid: 35535 topic_id: 6500 reply_id: 22836[/import]

I said “something like,” not “this exact text.” You need to modify it so the removeEventListener() command points to your button. [import]uid: 12108 topic_id: 6500 reply_id: 22979[/import]