Can I set a number to change with a button?

Good evening everyone, so I want to know if I can do something…

When I click a button, a text change.

The context is, in Volleyball teams have two timeouts in a match, when someone presses the button to request a timeout, the text above showing how many timeouts are available (2) will change to one (1) timeout available, and when it pressing again will change to zero (0) timeouts.

Can someone help me?
Thanks… :slight_smile:

opera_JcrJlKf17k

Create a number pageVar (if user stays on the same page while using the app) or appVar (if user can browse to other pages while using the app). Name it ‘timeoutCounter’ for example.
Assign the variable an initial value of 2.
On the component tap event of the button, attach a set pageVar (or set appVar) and bind it to the variable timeoutCounter you’ve just created.
Open the formula composer inside the assign value binding of the variable and make a formula like pageVar.timeoutCounter - 1
But you don’t want to go below 0 so add a condition to this formula so that if pageVar.timeoutCounter < 0 then 0, else pageVar.timeoutCounter - 1

1 Like

Thank you very much for your answer, if it’s not too much to ask, could you make a video? I tried to do it following your instructions but it didn’t work, if you don’t want to, that’s okay. Thanks!

set the variable (either pageVar or appVar)
image

Bind text value to variable
image

Once button added, attach a set pageVar or appVar to the button’s component tap and use the variable you’ve just created
image

The assigned value of this set pageVar (or appVar) is the formula I gave you further above.
image

1 Like