HIde a button after pressing it and show a new one

Hello, I’m currently working on a project where whenever a button is pressed it becomes hidden and a new button is shown. The thing is that I can create a function that will hide the button but am unable to add it into the button. Any thoughts or suggestions?

Is there a way to add an onRelease event function after creating the button or is that not possible?

Hi @eshangray,

The most helpful thing is for you to provide some basic code on what you’re currently doing. This way, other devs and staff can see how you’ve set up your button and listeners, then help you in solving this.

For clarity in the forums, please surround your code with “lua” tags like this:

[lua] -- Your code [/lua]

Best regards,

Brent

Okay, the main issue is I’m very new to all this so here it goes.

My code uses the generic widget.newButton, with various options that are not relevant at this time. The function I have right now is:

[lua]

local function hidebutton(event)

      if (event.phase == “ended”) then

               button.isVisible=false

[/lua]

This is all I want to do but I can’t seem to get it to work. Any thoughts or suggestions would be appreciated. Thank you and apologies if this dosen’t help.

How are you making your buttons?

Custom or widget?

Regular widget.

There are many ways to do this, and I’m a little unclear on what you are trying to do, however… using just the code from the button docsI can create two buttons that when pressed will hide themselves and show the other button.

local widget = require( "widget" ) local button1 local button2 local function handleButtonEvent( event ) if ( "ended" == event.phase ) then self.isVisible = false if( event.target == button1 ) then button2.isVisible = true else button1.isVisible = true end end end button1 = widget.newButton( { left = 100, top = 200, label = "Button 1", onEvent = handleButtonEvent }) button2 = widget.newButton( { left = 100, top = 200, label = "Button 2", onEvent = handleButtonEvent })

Hey roaminggamer, thanks for that but still nothing happens. I am using corona’s composer to create scenes so could this be part of the issue?

I should say that when I add your code I cannot interact with your buttons at all.

Create a standalone project with just main.lua and get your button working, then move on to integrating your solution into your scene.

Not my buttons.  Button code taken right from the docs and modified a little to show you the concept.  

Pay attention to the methodology used, not the specific example.  I didn’t run that example.

Treat it like pseudo code and try to understand what I was doing, then make your own buttons (in a test bench) following the same recipe.

Hi @eshangray,

The most helpful thing is for you to provide some basic code on what you’re currently doing. This way, other devs and staff can see how you’ve set up your button and listeners, then help you in solving this.

For clarity in the forums, please surround your code with “lua” tags like this:

[lua] -- Your code [/lua]

Best regards,

Brent

Okay, the main issue is I’m very new to all this so here it goes.

My code uses the generic widget.newButton, with various options that are not relevant at this time. The function I have right now is:

[lua]

local function hidebutton(event)

      if (event.phase == “ended”) then

               button.isVisible=false

[/lua]

This is all I want to do but I can’t seem to get it to work. Any thoughts or suggestions would be appreciated. Thank you and apologies if this dosen’t help.

How are you making your buttons?

Custom or widget?

Regular widget.

There are many ways to do this, and I’m a little unclear on what you are trying to do, however… using just the code from the button docsI can create two buttons that when pressed will hide themselves and show the other button.

local widget = require( "widget" ) local button1 local button2 local function handleButtonEvent( event ) if ( "ended" == event.phase ) then self.isVisible = false if( event.target == button1 ) then button2.isVisible = true else button1.isVisible = true end end end button1 = widget.newButton( { left = 100, top = 200, label = "Button 1", onEvent = handleButtonEvent }) button2 = widget.newButton( { left = 100, top = 200, label = "Button 2", onEvent = handleButtonEvent })

Hey roaminggamer, thanks for that but still nothing happens. I am using corona’s composer to create scenes so could this be part of the issue?

I should say that when I add your code I cannot interact with your buttons at all.

Create a standalone project with just main.lua and get your button working, then move on to integrating your solution into your scene.

Not my buttons.  Button code taken right from the docs and modified a little to show you the concept.  

Pay attention to the methodology used, not the specific example.  I didn’t run that example.

Treat it like pseudo code and try to understand what I was doing, then make your own buttons (in a test bench) following the same recipe.