Creating a "counter" function

Hi, I’ve been attempting to create a counter for one of my designs. It should work by this condition:

Assuming there are 5 total actions, if there is 1 checked item, display “4 action remaining”. If there are 2 checked items, display “3 actions remaining” and so on. I’ve tried to play with the visibility variable for a case but ran into some problems when accounting for different checked items.

Is there an easier solution creating a counter?

The easiest way would be to have a single variable. Let’s called it Counter. Assuming all your checkboxes start out unchecked, make the default value 0.

Then on each checkbox, when the box is checked set the Counter variable to [[Counter + 1]] and when it’s unchecked set the Counter variable to [[Counter - 1]]. Then on both cases (checking and unchecking) set the text on your label: [[Counter]] items remaining.

Thank you for the quick reply @nkrisc! I’ve created a variable called ‘Counter’ and am currently trying to set variable values for each checkbox. Unlike a standard checkbox, I’ve made it so that a checkmark image would show up in a box when a button is clicked. Would I have to set the variable value to [[Counter + 1]] or a whole digit like “2”?

The point of doing [[Counter + 1]] is that it adds 1 to whatever value the variable already has. This way if you have multiple checkboxes you can check or uncheck them in any order and the variable will always show the correct amount checked checkboxes.

You could hardcode a number for each checkbox, but then if you click them in a different order and select some then deselect some it will almost certainly be wrong.

1 Like

Thanks so much @nkrisc. You’ve put me in the right direction

Hi, I’m having some trouble getting a favorites counter to work as desired. Looking for some help.

I have the counter function set up ok. A total-favorites-heart starts in a disabled state, when an item is favorited the the total-favorites-heart becomes enabled and displays the sum # of items favorited.

My problems are:

One: making the total favorites heart become disabled and not show text when the number of favorites = 0

Two: persisting the items favorited across pages. Do I need to make a global variable for each item? There may be many (products), is there another way?

Example file is attached. It seems more complicated than it should be, I’m sure there is a more elegant solution.

Thank you!

FavTest.rp (46.8 MB)