Widget.newButton

Hello all, I am trying to use one button with two labels, so my code below shows how I am trying to do it but I know it is wrong because it is not working. So how to incorporate two labels on one button for two different functions. This code produces errors I have tried multiple versions of the below. Any Help is appreciated. 

local startButton = widget.newButton 

{

if countDownEngaged == false then

       left = 20,

        top = screenH / 2 ,

         id = “startButton”,

          label = “Start”,

            onEvent = startClock 

      else 

           left = 20,

            top = screenH / 2 ,

              id = “startButton”,

                label = “Stop”,

                  onEvent = startClock 

  

      end

  

}

Regards

JZ 

Suggest creating the button with the label that you would expect to see most often and then use the 

setLabel() method in your if/then block to adjust the label as needed. 

See : http://docs.coronalabs.com/api/type/ButtonWidget/setLabel.html

Something like this : 

local startButton = widget.newButton { left = 20, top = screenH / 2 , id = "startButton", label = "Start", onEvent = startClock } if countDownEngaged then startButton:setLabel( "Stop" ) else startButton:setLabel( "Start" ) end

Hope this helps.

Hello Ksan, the issue is actually with the if statement, this is the error      : unexpected symbol near ‘if’ 

ideas ?

JZ 

I See !! Thanks much will give that a try. 

JZ 

Yup. Just tested this code snippet for you and confirmed that it works. Best of luck. 

Ksan, thanks so much, I had to make a few tweaks but it is working perfectly now.

Much appreciated.

JZ 

Suggest creating the button with the label that you would expect to see most often and then use the 

setLabel() method in your if/then block to adjust the label as needed. 

See : http://docs.coronalabs.com/api/type/ButtonWidget/setLabel.html

Something like this : 

local startButton = widget.newButton { left = 20, top = screenH / 2 , id = "startButton", label = "Start", onEvent = startClock } if countDownEngaged then startButton:setLabel( "Stop" ) else startButton:setLabel( "Start" ) end

Hope this helps.

Hello Ksan, the issue is actually with the if statement, this is the error      : unexpected symbol near ‘if’ 

ideas ?

JZ 

I See !! Thanks much will give that a try. 

JZ 

Yup. Just tested this code snippet for you and confirmed that it works. Best of luck. 

Ksan, thanks so much, I had to make a few tweaks but it is working perfectly now.

Much appreciated.

JZ