how to get an event listener to only work under certain "if" conditions

for instance having the event listener only work if a statement is true, and if not then it will no longer respond to clicks or whatever.
By statement for instance I started out saying red = true, and after the clicking on the object (a button) it refers it to the function buttonHandler and one of the things this function does is sets the statement to red = false. This way the next time someone clicks on the button, red will now equal false which will keep the listener from referring to buttonHandler. Here is a segment of my work so far:

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

end

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

end

button: addEventListener ("touch", buttonHandler)

do you want it to actually remove the button handler or just do something different?

I want the buttonHandler to do something different depending on whether or not red = true or red = false

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local red = true
 
local function buttonHandler (e)
 
  if(e.phase == "began") then
 
    if(red == true) then
 
      audio.play (knock);
      red = false 
 
    elseif (red == false) then
 
      audio.play (knock);
 
    end
  end
end
 
button: addEventListener ("touch", buttonHandler)

Thanks so much for your help, it worked!

views:1488 update:2011/10/6 9:28:12
corona forums © 2003-2011