Countdown counter

I created a card that I have put in a variable “pageVars.counter-1” that should count from 5 to 0 when you click the button. The problem I need help with is that it did not stop at 0, it continues with -1, -2, -3 and so on.
What are the other parameters of “pageVars.counter”.
And I want help with a reset button to reset counter from 0 to default number.

Use a formula that checks the value of the display to see if it drops below the minimum you want to display. You can do this alot of ways, but an IF would work just fine.

Alternatively, use a formula to do the check for value and then stop the counter from counting down once it reaches your minimum.

Thanks KRB for your answer.
Can you please explain a little more how to do it?
And I want to know how I can reset the counter to the default number?

If you’re doing this as a button click that just counts down every time it’s clicked, you can do this a bit easier.

For the button itself, go to Display or Disabled (pick one, depending upon your UI/UX ideas) and set the value of Display or Disabled to a Formula: IF(theCounterVariable <= 0, true, false)

This way, the button will either disappear or be unclickable once the counter hits 0.

1 Like

Resetting the counter to a default number is the same as anything else: set the counter variable to a number using “Set page variable” and connect it to whatever trigger you want to use to force a reset of the counter.

Thanks so much :grinning:
I’ll test

1 Like

Hi, you can also use the MAX and MIN formulas for these use cases to keep the number within a certain limit.

If you set the number to MAX([pageVars.counter-1, 0]) it will work but never go below zero. :slight_smile:

Hi Mari,

Yes, it works now and it stays at 0.
Thank you so much for your help :slight_smile:
If I want to create a button to reset the counter from “0” to the default number (5) how do I do that?

Create the button and use “Set page variable” as you have done with this button :slight_smile:

1 Like

Thanks, it works Mari :slight_smile:
Now comes another question!

How do I put the reset button in the green button to make the whole button look like this?
Capture2

Hi, that’s not possible with the button components. You can use containers instead :slight_smile:

1 Like

Ok, I tried to put an icon instead of text in Card, which I was going to connect to the counter variable, but unfortunately it did not work.
What do you mean by containers?
I have put both the card and the button in a container, but it looks like two buttons.
I want it to look like one button!

The button component won’t let you put another button inside, so you will have to have a Container component with another Container (or a Button) inside to make the “outer button”. Like this:

Then you can use the Style and Layout tab options to make it look like you want it to :slight_smile:

Hi Mari,
The button ended up like this in the end :slight_smile:
I used “Row” instead of “Container”, it became much easier to adjust the button.

One more question if you can handle me!
I want to give app users the option to choose whether they want to use click sounds or vibration when they click the button.
Is this possible?
Thought put it in app settings!

Hi, looks great! You could use a combination of the “If statement” (to check the setting), “Vibrate” and “Play audio” flows for that :slight_smile:

Hi Mari,
I have tried to connect sound to the button but unfortunately did not succeed :frowning:
Can you please explain a little more how to fix it?

Hi user25

Hope you are having a very good morning, day or evening wherever you are?

Can you screenshot your flow for the Play Audio, just so I can understand what part is not succeeding or you?

Just be aware you are required to have an Audio Playback ID. There are some option inputs too like: Loop audio and the number of loops.

Hi James,
Also hope you have a great morning or evening!
What I want to do is when you click on the “counter” button, a click or a vibration is heard.
Audio files I was going to use are the ones that are in Android

I know that there was a problem in 2020 with android phones not playing correctly, an android problem rather than appgyver, something to do with files not being found.

What is the filepath you are looking for exactly, so I can look for a work around.

It works via a weblink, but I feel in this case you would rather keep it away from the internet, maybe an offline app etc.

Hi Drizzy,
Thanks for your reply :slight_smile:
I’m most interested in vibration when clicking the button, but there are users who want a beep instead.
The best solution is if it is possible to integrate an audio file in the app! because the app is running offline.