Building a counter

Hello!
I want to build a counter that counts the number of items added to a basket. It’s supposed to be easy, and i understand the logic, but everything i tried doesn’t work.
My logic is -

  1. At the begining, the counter field = 0
  2. The workflow of the button of the item: counter = counter + 1
  3. The counter should be shown near the basket icon. So i add a group, and inside the group a text box, which take the data from the database.
    Please help :slight_smile:

Hi Ilona,

There are a couple of ways to go about this, and it sounds like you’re on the right track. For your basket, you can add a “thing” to your database each time a user adds an item to the basket (which might be the best approach, since it allows you track things like abandonment) - that sounds like what you’re doing. I’ve done a quick test, creating a “State” on the basket icon instead. For either approach, you will just need to create the text component that will show the count, and then set the value (the very top input box in the inspector dialog) to something like “My Basket Name’s items:count” (see the attached images). You can do this in the “Insert dynamic data” dialog, which you can find by clicking the “Insert Dynamic data” button.


Hope this helps!

-Jon

A cool little trick i figured out to do this so you dont have to create multiple entries in a data base is to do the following:

Create 1 thing - for that thing create two Values and set the first default value to 0.
T1 - V1
T1 - V2

Then in your workflow to add 1, lets call it button +, you set up a loop to do the following.

  • = V1 get V2’s value and + 1, then for V2 change it to V1’s value

for button - it would be

  • = V1 get V2’s value and - 1, then for V2 change it to V1’s value

This lets you create a networked counter with multiple logins and locations.

1 Like