How can I stop multiple button presses ?

Hi,

On my app I have a “share on FB” button, how can I code it so the user can’t press multiple times on the button quickly ?

The button basically posts a photo onto FB and I have just tested it and by accident clicked it 3 times. Good test mind you as the image did in fact post 3 times to FB!

Cheers,

Dave [import]uid: 117617 topic_id: 22150 reply_id: 322150[/import]

You could set a flag on your button press function and when user presses the button the flag changes and after a certain amount of time the flag is set back to allow the user press again.
Or the button press function can be called by a timer which can only be pressed every xx time.

Hope this helps,
LeivaGames [import]uid: 30314 topic_id: 22150 reply_id: 88085[/import]

Set a flag to true on press, then, test for it in your button press function. The code below will reset the flag back to false and allow you to press again after 1000 ms, (1 second).

if myFlag == true then
return true
else
myFlag = true
timer.performWithDelay(1000, function() myFlag = false end)
end

[import]uid: 8872 topic_id: 22150 reply_id: 88096[/import]

Cheers guys.

Dave [import]uid: 117617 topic_id: 22150 reply_id: 88101[/import]

Make sure you are testing the event.phase in the event handler.
if you dont wrap your code in

if event.phase == "ended" then  
  
... stuff  
end  

You will get a hit when the button is touched, another if the finger moves on it, and another when the finger is removed.
3 hits.

[import]uid: 108660 topic_id: 22150 reply_id: 88102[/import]

Ah of course, thats why am getting multiple hits on the button.

Dave [import]uid: 117617 topic_id: 22150 reply_id: 88103[/import]

Thanks for this, and also Jeff. I’m using this in my app now and it’s doing the trick.

Tony [import]uid: 111970 topic_id: 22150 reply_id: 100417[/import]