Why are my Button Suddenly Not Working

For some reason my buttons just stopped working and I can’t figure out why. They work fine in the simulator so I’m not sure what’s up. Here’s my button code and the function that it’s sent to:

local function lev3(event) composer.gotoScene("level3") end button3 = display.newImage("playlevel3.png") button3.xScale=.3 button3.yScale=.3 button3.x = centerX button3.y = centerY sceneGroup:insert(button3) button3:addEventListener("tap",lev3)

Try this

button3:addEventListener( "touch", lev3 )

–SonicX278

Ohh and put the function below the image. Its better practice to use scope.

–SonicX278

Tried that and it’s still not working SonicX278. Not sure what’s going on.

Make a sample project of it not working and post it?

–SonicX278

SonicX278, this is inside composer. Function goes above display objects. Besides the function and the button there’s really nothing else to show. The display object is in the create scene. The Function is before the Create scene. I have local button3 in the forward references. This is what I tried when you said try touch instead of tap.

local function lev3(event) if ( event.phase == "began" ) then composer.gotoScene("level3") elseif ( event.phase == "ended" ) then end return true end

If what i said in the first post doesn’t work then please make a sample of it not working and post it… What build are you on? 

–SonicX278

I just download the latest build but haven’t updated yet. The build I am currently using is 2646.

Update to current and get back to us.

–SonicX278

Thanks Sonic. OK. I have Updated and still nothing. It was working yesterday. Now nothing.  I have made a ton of apps and I have never had this problem in Corona. I mean it’s just a basic button but I can’t figure out what the deal is. There’s really not much to see in the code besides what I’ve posted. But obviously something is wrong. Do you want me to post the .APK?

That’s weird. Have you tried a widget.newButton.?

–SonicX278

Not yet but I want the button to look a certain way so I stay away from widgets, but I’ll give it a try. This is been giving me a pain in the ass all day.

Hmm this is not right. If this was working before… Did you change anything that made it not work? Have you tried making a button in just a main.lua? 

–SonicX278

I feel like your image you are using for a button is corrupt… Try a different image and retype the code manually don’t just copy and paste.

–SonicX278 

It sounds to me like a scope problem.

“Function goes above display objects, the display object is in create scene, the function is before create scene…”

Should it not be…

  1. Create the display object

  2. Then the function

  3. Then the touch listener

Thanks for the response QuizMaster, I have never heard that before when it comes to composer. Functions go above the create Scene and Display Objects are located in the Create Scene that’s how I was taught but I’ll give it a try. Sonic I have tried a few different Images so that’s not it.

Tried that Quizmaster and it doesn’t work.

There may be case-sensitivity issues if it works on simulator but not the device. If you’re using Android, you can look it up with logcat. On iOS, try XCode console.

By the way, you can also make custom buttons with widgets. It has many features that you can use to create a good looking button.

Ok Guys, here’s what it was. bgmadclown you were right. The problem had nothing to do with the button. My set up was fine. The problem also was not in the scene that the button was even in. Believe me, I thoroughly examined each page so many times that my head was about to implode. The problem was in the scene that  the button sent you to and it was a case-sensitive thing like bgmadclown said. I think what had me stumped is that it never went to the page on the device that the button was supposed to send you so I figured at first, it was something to do with that page. Logically, I also looked over everything in the page the button was connected to as well but I just could not see it. Probably doesn’t help that I’m dyslexic but I ended up finding it in an error that I created trying everything that I possibly could. Next time I am having this much of a problem figuring it out I will know that it’s probably a case-sensitive thing. I have had this happen before to me but never have I spent two days wasting my time on a lowercase ‘l’ that was supposed to be an uppercase ‘L’. Damn is all I can say and move on. Don’t let this happen to you. Thanks for the support from bgmadclown, Quizmaster and SonicX278 because without you guys all my hair would be gone.

Just FYI, the original code was fine.  “tap” is a perfectly valid way to handle buttons and I didn’t see any scope issues. The lev3 function was defined before it was used.

Glad it was something simple like a case sensitivity problem. If you ever run into a problem where “It works in the simulator, but not on the device”, the first thing to look at is case sensitivity problems.  Also had you looked in the console log (adb logcat) on your android device (or Xcode’s Devices screen" for iOS devices), there would have been a warning about not being able to open the file. I wish it was an error, not a warning, but . . .

Rob