Need some serious debugging help from a professional!

Please contact me under contact@courli.net

I have some Problems with Buttons under some android devices like Samsung Tab3.

Please send some references…

You could be helped faster if you were to paste certain code which is causing issues…

Ok - here is the problem: I have a world menu and a level menu, which can be scrolled by touching the screen sideways. If you tap on a world or a level, you get into the game.
 
The problem is, that on some Android devices (e. g. Samsung Tab3), the scrolling works fine - but when you tap on a button, nothing happens. After tapping appr. 10 times, the button works…
 
It’s really strange! On iPhone, Kindle etc. everything works fine…
 
Here is the code:

------------------------------------------------------------------ -- Switch between Level and World Pages ------------------------------------------------------------------ local touchScreen = function(event) -- handles runtime touch events on screen (for swiping) --if gameLoop == 0 then local diffX -- set up variable to store the X distance the finger has moved if event.phase == "began" then startTime = system.getTimer() -- get the time the finger first touches the screen display.getCurrentStage():setFocus(event.target) end if event.phase == "moved" and pages \> 1 and gameLoop==0 then -- if there are pages to swipe to display.getCurrentStage():setFocus(event.target) -- avoids problems on some android devices where touches on buttons aren't registered moving = true -- set a variable that states the user is currently moving their finger diffX = event.x - event.xStart -- calculate the X distance the finger has moved if math.abs(diffX) \> 1 then -- if the finger has moved \> 1 pixel levelGroup.x = -pageOffset \* (page - 1) levelGroup.x = levelGroup.x + diffX -- move the menu group along with the finger end end if event.phase == "moved" and settings.maxepisodes \> 1 and gameLoop==6 then -- if there are pages to swipe to display.getCurrentStage():setFocus(event.target) -- avoids problems on some android devices where touches on buttons aren't registered moving = true -- set a variable that states the user is currently moving their finger diffX = event.x - event.xStart -- calculate the X distance the finger has moved if math.abs(diffX) \> 1 then -- if the finger has moved \> 1 pixel worldGroup.x = -worldOffset \* (worldpage - 1) worldGroup.x = worldGroup.x + diffX -- move the menu group along with the finger end end if event.phase == "ended" then display.getCurrentStage():setFocus(nil) -- avoids problems on some android devices where touches on buttons aren't registered moving = false -- reset variable as user no longer moving finger local moved -- temp variable to store which direction the user swiped diffX = (event.x - event.xStart) -- get the final amount of movement local absX = math.abs(diffX) -- get the absolute amount of movement irrespective of direction local endTime = system.getTimer() -- get the time the movement ended local moveTime = endTime - startTime -- calculate the total amount of time the finger touched the screen if diffX \> 0 then moved = "left"; end if diffX \< 0 then moved = "right"; end -- calculate which direction the user swiped local threshold = 15 -- sets a threshold for number of pixels the user must move finger to constitute a swipe if moveTime \> 500 then threshold = 100; end -- if the user moved finger slowly increase the threshold if moved == "left" and absX \> threshold and page \> 1 and gameLoop==0 then -- if the finger swiped left far enough and there is a page to the left to swipe to --swipe() page = page - 1 episodeDB[worldpage]["page"] = page ggEpisodes:save() end if moved == "left" and absX \> threshold and worldpage \> 1 and gameLoop==6 then -- if the finger swiped left far enough and there is a page to the left to swipe to --swipe() worldpage = worldpage - 1 settings.currentEpisode=worldpage settings:save() end if moved == "right" and absX \> threshold and page \< pages and gameLoop==0 then -- if the finger swiped right far enough and there is a page to the left to swipe to page = page + 1 episodeDB[worldpage]["page"] = page ggEpisodes:save() --swipe() end if moved == "right" and absX \> threshold and worldpage \< settings.maxepisodes and gameLoop==6 then -- if the finger swiped right far enough and there is a page to the left to swipe to worldpage = worldpage + 1 settings.currentEpisode=worldpage settings:save() --swipe() end if gameLoop == 0 then transition.to(levelGroup, { x = -pageOffset \* (page - 1), time = 1400, transition = easing.outExpo }) end if gameLoop == 6 then transition.to(worldGroup, { x = -worldOffset \* (worldpage - 1), time = 1400, transition = easing.outExpo }) bg:setFillColor(episodeDB[worldpage]["r"],episodeDB[worldpage]["g"],episodeDB[worldpage]["b"]) end -- move to the appropriate page startTime = 0 -- reset startTime end --end end 

And the button:

local touchWorld = function (event) -- function to handle touching of menu buttons local obj = event.target -- localise button pressed local bid = obj.id -- get the ID of the button pressed if event.phase=="began" then display.getCurrentStage():setFocus(event.target) end if event.phase == "ended" and moving == false then --doink(obj) display.getCurrentStage():setFocus(nil) -- avoids problems on some android devices where touches on buttons aren't registered --worldpage = bid -- store the level to be loaded playsound(sounds["click"]) -- play a click sound --timer.performWithDelay( 400, menuGame ) menuGame() end end

Instead of trying to use a touch function to handle tap functionality I think you should try using a tap function just for the button. That way any actual touch events / scrolling / etc happening in the touchScreen function will be ignored.

Having a clean tap only function:

local tapWorld = function (event) local obj = event.target local bid = obj.id if (bid=="unique button id here") then --doink(obj) --worldpage=bid playsound(sounds["click"]) menuGame() end return true end

BTW I also did notice you are not using “return true” at the end of your touch events… this prevents firing multiple objects that have event listeners when layered (a must have). Make sure to update the button’s addEventListener(“touch”) > addEventListener(“tap”)

Let me know if that works!

Wow!

Thank you so much! That helped me alot.

You could be helped faster if you were to paste certain code which is causing issues…

Ok - here is the problem: I have a world menu and a level menu, which can be scrolled by touching the screen sideways. If you tap on a world or a level, you get into the game.
 
The problem is, that on some Android devices (e. g. Samsung Tab3), the scrolling works fine - but when you tap on a button, nothing happens. After tapping appr. 10 times, the button works…
 
It’s really strange! On iPhone, Kindle etc. everything works fine…
 
Here is the code:

------------------------------------------------------------------ -- Switch between Level and World Pages ------------------------------------------------------------------ local touchScreen = function(event) -- handles runtime touch events on screen (for swiping) --if gameLoop == 0 then local diffX -- set up variable to store the X distance the finger has moved if event.phase == "began" then startTime = system.getTimer() -- get the time the finger first touches the screen display.getCurrentStage():setFocus(event.target) end if event.phase == "moved" and pages \> 1 and gameLoop==0 then -- if there are pages to swipe to display.getCurrentStage():setFocus(event.target) -- avoids problems on some android devices where touches on buttons aren't registered moving = true -- set a variable that states the user is currently moving their finger diffX = event.x - event.xStart -- calculate the X distance the finger has moved if math.abs(diffX) \> 1 then -- if the finger has moved \> 1 pixel levelGroup.x = -pageOffset \* (page - 1) levelGroup.x = levelGroup.x + diffX -- move the menu group along with the finger end end if event.phase == "moved" and settings.maxepisodes \> 1 and gameLoop==6 then -- if there are pages to swipe to display.getCurrentStage():setFocus(event.target) -- avoids problems on some android devices where touches on buttons aren't registered moving = true -- set a variable that states the user is currently moving their finger diffX = event.x - event.xStart -- calculate the X distance the finger has moved if math.abs(diffX) \> 1 then -- if the finger has moved \> 1 pixel worldGroup.x = -worldOffset \* (worldpage - 1) worldGroup.x = worldGroup.x + diffX -- move the menu group along with the finger end end if event.phase == "ended" then display.getCurrentStage():setFocus(nil) -- avoids problems on some android devices where touches on buttons aren't registered moving = false -- reset variable as user no longer moving finger local moved -- temp variable to store which direction the user swiped diffX = (event.x - event.xStart) -- get the final amount of movement local absX = math.abs(diffX) -- get the absolute amount of movement irrespective of direction local endTime = system.getTimer() -- get the time the movement ended local moveTime = endTime - startTime -- calculate the total amount of time the finger touched the screen if diffX \> 0 then moved = "left"; end if diffX \< 0 then moved = "right"; end -- calculate which direction the user swiped local threshold = 15 -- sets a threshold for number of pixels the user must move finger to constitute a swipe if moveTime \> 500 then threshold = 100; end -- if the user moved finger slowly increase the threshold if moved == "left" and absX \> threshold and page \> 1 and gameLoop==0 then -- if the finger swiped left far enough and there is a page to the left to swipe to --swipe() page = page - 1 episodeDB[worldpage]["page"] = page ggEpisodes:save() end if moved == "left" and absX \> threshold and worldpage \> 1 and gameLoop==6 then -- if the finger swiped left far enough and there is a page to the left to swipe to --swipe() worldpage = worldpage - 1 settings.currentEpisode=worldpage settings:save() end if moved == "right" and absX \> threshold and page \< pages and gameLoop==0 then -- if the finger swiped right far enough and there is a page to the left to swipe to page = page + 1 episodeDB[worldpage]["page"] = page ggEpisodes:save() --swipe() end if moved == "right" and absX \> threshold and worldpage \< settings.maxepisodes and gameLoop==6 then -- if the finger swiped right far enough and there is a page to the left to swipe to worldpage = worldpage + 1 settings.currentEpisode=worldpage settings:save() --swipe() end if gameLoop == 0 then transition.to(levelGroup, { x = -pageOffset \* (page - 1), time = 1400, transition = easing.outExpo }) end if gameLoop == 6 then transition.to(worldGroup, { x = -worldOffset \* (worldpage - 1), time = 1400, transition = easing.outExpo }) bg:setFillColor(episodeDB[worldpage]["r"],episodeDB[worldpage]["g"],episodeDB[worldpage]["b"]) end -- move to the appropriate page startTime = 0 -- reset startTime end --end end 

And the button:

local touchWorld = function (event) -- function to handle touching of menu buttons local obj = event.target -- localise button pressed local bid = obj.id -- get the ID of the button pressed if event.phase=="began" then display.getCurrentStage():setFocus(event.target) end if event.phase == "ended" and moving == false then --doink(obj) display.getCurrentStage():setFocus(nil) -- avoids problems on some android devices where touches on buttons aren't registered --worldpage = bid -- store the level to be loaded playsound(sounds["click"]) -- play a click sound --timer.performWithDelay( 400, menuGame ) menuGame() end end

Instead of trying to use a touch function to handle tap functionality I think you should try using a tap function just for the button. That way any actual touch events / scrolling / etc happening in the touchScreen function will be ignored.

Having a clean tap only function:

local tapWorld = function (event) local obj = event.target local bid = obj.id if (bid=="unique button id here") then --doink(obj) --worldpage=bid playsound(sounds["click"]) menuGame() end return true end

BTW I also did notice you are not using “return true” at the end of your touch events… this prevents firing multiple objects that have event listeners when layered (a must have). Make sure to update the button’s addEventListener(“touch”) > addEventListener(“tap”)

Let me know if that works!

Wow!

Thank you so much! That helped me alot.