Buttons broken after setEnable(true) & toFront() toggle

I am trying to control the flow of my app by disabling buttons and showing that they are disabled by sending them behind an opaque background. After a few cycles of this all the buttons freeze and no longer work.

An example of what I am doing is attached as a zip.

I’m on Windows trying out Lua Glider and Sublime Text.

I’m not out of the simulator with my issue but will want to deploy on iOS & Android.

Version: 3.0.0, Platform: iPad / x64 / 6.2 / Intel® HD Graphics 4400 / 4.3.0 - Build 20.19.15.4331 / 2015.2731

The main idea is that pushing some buttons should allow other buttons to be enabled and forward while still others are disabled and pushed back. This will direct the user to use the app correctly. In my example code, pushing B should enable A and disable B, then pushing A should enable B and disable A, ad nauseam. With my example I only get a half of a cycle and it all freezes up! “A” is forward but nothing happens on click and the “B” is stuck with the “over” attributes.

I’m missing something, several things, facepalm? Go easy…

Hi @clarkburbidge,

I would suggest using the “onRelease” listener option for your buttons, instead of “onPress”. In cases like yours, where you want to enable/disable buttons, it’s usually better to use “onRelease” because that indicates the user completed the entire action of pressing and lifting off the button.

So basically, in your code, just change both instances of “onPress” to “onRelease”.

Also, you should localize your buttons and background. Right now they’re global variables, and Lua globals are almost never good. If you’re relatively new to Lua, I suggest you study the concept of scope before you proceed too much further, as it’s an essential core topic that will come into play for nearly everything going forward. :slight_smile:

https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/

http://www.youtube.com/watch?v=2ATlcGP2zMY

Best regards,

Brent

Thanks Brent!

I found the answer between then and now that my topic posted. The lesson is RTFM. There is sure a lot of great info on the Corona site. The video Corona University - Creating Buttons in Corona SDK had the example code. It seems that the answer was similar to the one you gave.

To wrap it all up in a bow for the forum I have included my fixed example. For those who find this in the future note that my global vs local background and buttons are not up to par.

Enjoy!

Hi @clarkburbidge,

I would suggest using the “onRelease” listener option for your buttons, instead of “onPress”. In cases like yours, where you want to enable/disable buttons, it’s usually better to use “onRelease” because that indicates the user completed the entire action of pressing and lifting off the button.

So basically, in your code, just change both instances of “onPress” to “onRelease”.

Also, you should localize your buttons and background. Right now they’re global variables, and Lua globals are almost never good. If you’re relatively new to Lua, I suggest you study the concept of scope before you proceed too much further, as it’s an essential core topic that will come into play for nearly everything going forward. :slight_smile:

https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/

http://www.youtube.com/watch?v=2ATlcGP2zMY

Best regards,

Brent

Thanks Brent!

I found the answer between then and now that my topic posted. The lesson is RTFM. There is sure a lot of great info on the Corona site. The video Corona University - Creating Buttons in Corona SDK had the example code. It seems that the answer was similar to the one you gave.

To wrap it all up in a bow for the forum I have included my fixed example. For those who find this in the future note that my global vs local background and buttons are not up to par.

Enjoy!