[Resolved] double hit button

I’ve realized when i hit some buttons in corona sim and iOS sim, i got a double event

for example, this button

[lua] buttonFav = ui.newButton{
default = “anscaLogo.png”,
over = “anscaLogo.png”,
onEvent = buttonFavHandler,
id = “buttonFav”,
text = “F”,
font = “AmericanTypewriter-Bold”,
textColor = { 51, 51, 51, 255 },
size = 22,
emboss = true

}[/lua]

any idea about the problem? [import]uid: 60723 topic_id: 24608 reply_id: 324608[/import]

Your event, buttonFavHandler, add;

if event.phase == “ended”

That should fix it :slight_smile:

Alternatively, change onEvent to onRelease.

Peach [import]uid: 52491 topic_id: 24608 reply_id: 99725[/import]

thanks, it works :slight_smile:

[import]uid: 60723 topic_id: 24608 reply_id: 100323[/import]

Hi,

I have the same problem …

 function repeatQuestionTouch(e)  
 print("repeat Q was touched");  
  
 if (e.phase == "began") then  
 --return true;  
 end  
 if (e.phase == "moved") then  
 --return true;  
 end  
 if (e.phase == "ended") then  
 repeatQuestion();  
 return true;  
 end  
 end  

One touch; two print statements. Question’s audio doesn’t play twice. Same sitch with and without return trues.

Is there an error?

Thanks for any help.

Best,

Lynne [import]uid: 11631 topic_id: 24608 reply_id: 100355[/import]

Put the print inside the if (e.phase == “ended”),

for some reason the event is generated twice but the phase control works ok. [import]uid: 60723 topic_id: 24608 reply_id: 100357[/import]

excellent. thanks, Pablo. [import]uid: 11631 topic_id: 24608 reply_id: 100362[/import]

It does it twice because it’s not within any of the if statements checking for event phases - putting it under “ended” or “began” it will fire once.

I know this is resolved now but just wanted to explain why it was happening :slight_smile: [import]uid: 52491 topic_id: 24608 reply_id: 100386[/import]

ah, perfect

thanks for the explanation :slight_smile: [import]uid: 60723 topic_id: 24608 reply_id: 100392[/import]

Peach, you mind reader :slight_smile: i’ll spare you my asynchronous loop theory … and, thank you for the straight up truth. you rock, as always. best, L [import]uid: 11631 topic_id: 24608 reply_id: 100420[/import]

I’m having a similar problem with another button / handler.
I have two buttons associated to the handler.

to avoid the double touch i changed onEvent by onRelease but it launches me an error. It seems is because I use the event id to discriminate between buttons. So i added the if event.phase statement but now the instruction are not executed. I checked that the button is touched but none of the if (began, ended or cancelled) is executed.

button

[lua] backBtn = ui.newButton{
default = “backButton.png”,
over = “backButton_over.png”,
onEvent = backBtnHandler,
id = “back1”,
–text = “B1”
}[/lua]
Function

[lua]function backBtnHandler( event )

selfb = event
local backid = selfb.id

print(backid … " pressed ")

if event.phase == “began” then

print (“began”)

elseif event.phase == “moved” then

print (“moved”)

elseif event.phase == “ended” or event.phase == “cancelled” then
–if event.phase == “began” then

print (“ended”)
end

return true

end[/lua]
In this example I just got :

back1 pressed
back1 pressed

[import]uid: 60723 topic_id: 24608 reply_id: 100477[/import]

Hah, thanks Lynne, I do my best :slight_smile:

Pablo, you’re right, this does not seem right. I normally make my own buttons using sprites rather than using ui but I’m fairly confident this is a bug, or at least not as functional as it should be.

Could you zip a test case that we can run to demonstrate the issue and file a bug report using the link in the top right, please? It would be most appreciated.

It may be me misunderstanding something about ui.lua but it doesn’t seem right to me event phases pose issues, id or not. [import]uid: 52491 topic_id: 24608 reply_id: 100501[/import]

no problem, i’ll do it
[import]uid: 60723 topic_id: 24608 reply_id: 100570[/import]

I’m not sure whether this helps; but, yesterday, print statements indicated that the touch-event function is not reading its ‘if’ statements in direct sequence, meaning it doesn’t proceed:

top (first line under function header) - began - moved - ended

It reads:

top - began - top - moved - top - ended

In my case, there’s an external function in ended. When relocated to began, read order is:

top - began - (ignores moved) - top - ended

It seems touch-event functions prefer that you limit what they’re being asked to do, or weird things happen (i.e., sound played twice until I called audio.play with an external function).

Could function read order be a factor … have potential to cause problems? Maybe it’s reading exactly as intended. They ‘meant’ to do that :slight_smile: Regardless, keeping it simple and outsourcing to external functions helped in my case.

I’m no system software engineer. Just sayin’ :slight_smile: [import]uid: 11631 topic_id: 24608 reply_id: 100597[/import]

bug submitted [import]uid: 60723 topic_id: 24608 reply_id: 101439[/import]

It seems it wasn’t a bug. That 's the answer I got

Hello there.

widget.newButtons event.phase only respond to the following:

“press”, “move”, "release"

Here is your example modified to work with widget buttons:

[code]
local ui = require(“ui”)
local widget = require “widget”
newButton = widget.newButton

local function backBtnHandler( event )

local backid = event.id
print(backid,“state:”,event.phase)

if event.phase == “press” then
–print(backid,“pressed”)
elseif event.phase == “release” then
–print(backid,“released”)
end

return true

end
local backBtn = ui.newButton{
default = “backButton.png”,
over = “backButton_over.png”,
onEvent = backBtnHandler,
id = “back1”,
–text = “B1”
}
backBtn.x = 100
backBtn.y = 50
backBtn.alpha = 1
[/code] [import]uid: 60723 topic_id: 24608 reply_id: 101984[/import]

Hey, thanks for updating!

This is very useful info, I wasn’t aware of this though I certainly should have been.

Making a note to myself to have a play with this tonight and try to commit it to memory for the future.

:slight_smile: [import]uid: 52491 topic_id: 24608 reply_id: 102006[/import]