# Counter

The counter counts up or down from zero or a preset number every time the corresponding functions are triggered. A counter can also count into the negative.

To quickly start with counters:

1. Find the `Functions` panel on the left-hand side of the screen.
2. Expand `Utilities` and then `Counter.`
3. Create a counter instance with the [`create`](#create) function.
4. Expand the instance that appeared in the panel and get started with using the timer.

Use the [`create`](#create) and [`delete`](#delete) functions to manage the existing timers. Existing timers can be seen in the functions panel on the left under `Timer`. Yellow ones are not instantiated and green ones are ready for use.

## Creating a counter

To `create` a counter:

1. Insert a counter name in the yellow field.
2. Optionally insert a number for the initial state of the counter. (Only works if the counter is not yet instantiated.)
3. Click the trigger field to create an instance of the counter. You should see the counter in the functions panel go from yellow to green.

<div align="center"><figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FyEqMGcv8T9xbwZbiBGiX%2Fimage.png?alt=media&#x26;token=ffc22a36-c4c9-4a49-9f66-ff5f966cd9a9" alt=""><figcaption><p>Creating a counter with initial state of 55</p></figcaption></figure></div>

## Deleting a counter

To `delete` a counter:

1. Insert the name of the existing counter you want to delete in the yellow field.
2. Click the trigger field.

<div align="center"><figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FDzl363OhBrzAfXPRFAZZ%2Fimage.png?alt=media&#x26;token=dc9b4702-3fdf-4da4-890f-51be9946d1ad" alt="" width="563"><figcaption><p>Deleting a counter instance</p></figcaption></figure></div>

{% hint style="info" %}
The instance in the functions panel will turn yellow again, until the yellow field of the `create` function is cleared, or the `create` function is deleted from the board.
{% endhint %}

## Counter functions

To utilize counters, you can find functions tied to each instance when you expand the instance.

<div align="center"><figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FKByuJ8aD5761oAx7wMbF%2Fimage.png?alt=media&#x26;token=e2829763-0a1d-4ca1-bcd3-55881cfe01a3" alt="" width="299"><figcaption><p>Location of counter instances</p></figcaption></figure></div>

### Incrementing a counter

Triggering the `increment` function increases the counter by `1`.

<div align="center"><figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FixKxeX8gfSw2geA09aUt%2Fimage.png?alt=media&#x26;token=83d7393e-1d73-4d13-8b14-f5b5698b0e7b" alt="" width="563"><figcaption><p>Incrementing the counter</p></figcaption></figure></div>

### Decrementing a counter

Triggering the `decrement` function decreases the counter by `1`.

<div align="center"><figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2Ffnvb1q70przNaFXRRZMI%2Fimage.png?alt=media&#x26;token=da14d159-57e6-4578-9f4f-5055e0dae4d0" alt="" width="563"><figcaption><p>Decrementing the counter</p></figcaption></figure></div>

### Resetting a counter

With `reset` you can set the counter to `0` or a new specified state. The input field has initial greyed out in it, because in the future reset should reset the function to the initial state. As such, please always enter a number for now.

1. Insert or link a value in the input field.
2. Trigger the function.

<div align="center"><figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2Fk9bUDUvvynrd4IVYNlD4%2Fimage.png?alt=media&#x26;token=ef3aa792-7247-4f60-95d3-7e8a42910bef" alt="" width="563"><figcaption><p>Setting a new value for the counter</p></figcaption></figure></div>

### Getting the count

The `getCount` function returns the current count of the counter.

<div align="center"><figure><img src="https://3495989837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE5Ketpww1s7TauSAJrJ8%2Fuploads%2FIgvvgyKsrkHMhr4VEXH2%2Fimage.png?alt=media&#x26;token=609f5672-098d-4dd7-8c8e-c60aef6e89d5" alt="" width="563"><figcaption><p>Getting the counter state</p></figcaption></figure></div>
