EventListeners not working on Device

Hi,

I have touch event listeners for images of buttons (one and two player). The listeners work perfectly on the emulator, but when I build and installed on the device, only the one player button seems to work. Any idea? Corona has been extremely buggy for me. A lot of crashes awhile restarting builds. Let me know if this is a build in problem. I have had problems with building before, where my apps would just play a white screen at times, then when I go back to rebuild it 5-6 hours later, it works on the same code. 

This is most likely a problem with your code.  Please post the relevant code.  Also, be sure to give us some more information like which device, which version of Corona, etc.  Lastly, have you done any debuggingon the device?  Please do so and post the log messages.

I have already debugged on the device. The listener just did not run. The code is running on a Nexus 4. Posting on the forum absolutely my last resort. No log since it won’t recognize the touch for the listener on the device. 

 

function drinkListen\_onePlayer (event) local target = event.target local phase = event.phase --will pass true into the game's function for one player if ("began" == phase) then drinkGame (true) local menuSetting\_Resume = timer.pause (menuSetting\_Controller) end --return true end function drinkListen\_twoPlayer (event) local target = event.target local phase = event.phase --will pass false into the game's function for two player if ("began" == phase) then drinkGame (false) local menuSetting\_Resume = timer.pause (menuSetting\_Controller) local displayDebug = display.newText ("debug", 150, 150, native.systemFontBold, 30) end --return true end menuSuika\_onePlayer = display.newImage ("Suika\_Player1Button.png") menuSuika\_onePlayer.x = 98 menuSuika\_onePlayer.y = 125 menuSuika\_twoPlayer = display.newImage ("Suika\_Player2Button.png") menuSuika\_twoPlayer.x = 63 menuSuika\_twoPlayer.y = 125 menuSuika\_onePlayer:addEventListener ("touch", drinkListen\_onePlayer) menuSuika\_twoPlayer:addEventListener ("touch", drinkListen\_twoPlayer)

I’ve also notice that the APK builds are extremely inconsistent on their output sizes. I build the same code 10 times just to see:

18,008 k

18,010 k

18,008 k

18,068 k

18, 109 k

18,008 k

18,009 k

18,008 k

18,008 k

18,065 k

Try putting print statements in both functions (both inside and out of the if statements) and debug on device to see if they print.  

How would I debug if the listener won’t triggered? I also already tried throwing debug statements withing both of them.

Print statements are the simplest to use to test if the functions are working. Try it.

I did try that way of debugging. It just doesn’t seem to be working for some reason. One player button listener works perfectly every time, but two player won’t. They are the exact identical codes, just different naming. 

function drinkListen\_onePlayer (event) local target = event.target local phase = event.phase --will pass true into the game's function for one player if ("began" == phase) then drinkGame (true) local menuSetting\_Resume = timer.pause (menuSetting\_Controller) local showDebug = display.newText ("onePlayer Drinks", 100, 200, native.systemFontBold, 30) end return true end function drinkListen\_twoPlayer (event) local target = event.target local phase = event.phase --will pass false into the game's function for two player if ("began" == phase) then drinkGame (false) local menuSetting\_Resume = timer.pause (menuSetting\_Controller) local showDebug = display.newText ("twoPlayer Drinks", 100, 100, native.systemFontBold, 30) end return true end

I meant something like this:

function drinkListen\_onePlayer (event) local target = event.target local phase = event.phase print("onePlayer function works") --will pass true into the game's function for one player if ("began" == phase) then drinkGame (true) print("onePlayer drinkGame called") local menuSetting\_Resume = timer.pause (menuSetting\_Controller) end --return true end function drinkListen\_twoPlayer (event) local target = event.target local phase = event.phase print("twoPlayer function works") --will pass false into the game's function for two player if ("began" == phase) then drinkGame (false) print("twoPlayer drinkGame called") -- If this line doesn't print then something is wrong with your drinkGame function local menuSetting\_Resume = timer.pause (menuSetting\_Controller) end --return true end menuSuika\_onePlayer = display.newImage ("Suika\_Player1Button.png") menuSuika\_onePlayer.x = 98 menuSuika\_onePlayer.y = 125 menuSuika\_twoPlayer = display.newImage ("Suika\_Player2Button.png") menuSuika\_twoPlayer.x = 63 menuSuika\_twoPlayer.y = 125 menuSuika\_onePlayer:addEventListener ("touch", drinkListen\_onePlayer) menuSuika\_twoPlayer:addEventListener ("touch", drinkListen\_twoPlayer)

print will only work on the console. My problem isn’t with the emulator, its the device. My code runs perfectly on the emulator, but when it gets build into an APK, it refuse to work just only for that portion for “one/two player selection”. One player selection button works perfectly, but two player does not, they are the exact code.

Print statements work on the device.  That’s why I sent you the link on how to debug on the device.  And they are not exactly the same code, in one you have drinkGame(true), the other false.  I am inclined to think the problem might be here, in your drinkGame function.

I think my problem may be a corona-built-in issue. 

print(“twoPlayer drinkGame called”)

should execute regardless, when the function is called by the listener, but since the listener is not working, I don’t think it can call its respective function. I actually took the drinkGame() function out of the equation and it will still not print. What options do I have? Buy pro so it’ll fix my start-package problems?

I’m sorry I’m a little confused now.  So did you try the code I posted above, on the device, with the device connected to your computer and receiving the log messages?   If so, did you see the player one print statements?

What are you confused about? It is just listeners to an image that waits for touch events. My problem is that it does not run on the device,but does run on the emulator perfectly. Player one print statement does print. Player two print statement does not, as the listener does not work. How can I debug a bug when the bug is a built-in-issue? Or I could be wrong about this. But I can’t seem to figure out how identical code with different names could cause a problem, when about 40-50 buttons listener from the code works perfectly, except for this one listener.

Post your drinkGame code

I removed the drinkGame() function and it still will not print. Corona is very interesting. I did 20 builds over the pass 30 minutes and the more I build with the same exact code, the more thing starts to break. How could the same exact code do different things at different points? I’m just confused on this, I mean if this is a problem that can be solved by upgrading to “Pro” or another payment level, it’s not a problem. 

Who knows, I’m done trying here

Yeah, let me know if it’s an upgrade issues. Thanks for trying.

Doubt it.   BTW just noticed the timer line, it is awkward.  Why are you setting it to a local variable?  It is not a accessible outside of that if statement.

nhong, if you build the exact same code, using the same daily build, then it will do the exact same thing (well, unless you’re using random numbers, downloading something from the internet, etc.). If you’ve truly been experiencing different build behavior from the exact same code (including white screens or crashes like from your first post), then I’d more likely suspect there’s something wrong with your machine (virus?) than with Corona. Anyway, as to the issue you’re describing about touch listeners, it sounds strange. I don’t see anything obviously wrong with the code you posted. What would probably be most helpful is if you created a simple test project that you can share here and we could test. By that I mean project we could copy paste or download and run immediately without any fuss. (We can’t run your above code easily because it uses objects and images that we don’t have.) - Andrew