# Timer Blocks

## Adding Timers to your app

### Create a Timer

You can add a Timer to your app from the Blocks tab of your Thunkable project. Under the App Features header, click the ⊕ icon next to Timers to add a Timer to your app.

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MMGsCOQmypJUYH0PDNJ%2F-MMGuu2irLbUHCPC240O%2Ftimers.png?alt=media\&token=5651bf1b-65c1-4fa4-b09f-6a9b598a8244)

### Properties

The Timer's properties are initially set when you add a Timer to your project.&#x20;

| Property | Description                                                                                                                                            | Data Type  |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- |
| Interval | How regularly the Timer fires, in seconds or milliseconds                                                                                              | Number     |
| Count Up | Toggle whether the Timer's [time blocks](#get-time-in-seconds) return the current time as counted up from 0 or counted down from the interval duration | True/False |
| Loops    | Toggle whether the Timer will start again once it has fired                                                                                            | True/False |
| Enabled  | Toggle whether the Timer is active in your app                                                                                                         | True/False |

### Edit or Delete a Timer

You will see the Timers you have added to your app underneath the Timers section of your blocks. To edit the properties after the fact or delete a timer, click the gear icon next to the Timer's name in the left panel of the Blocks tab.&#x20;

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MMGsCOQmypJUYH0PDNJ%2F-MMGv4zCzvvI2RLgDMSN%2Ftimers-menu.png?alt=media\&token=5ead98d5-d29d-4e2f-8df8-d8d429f1615b)

## Blocks

### Events

#### When Timer Fires

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MJWWgPcZZc65tAJb8I1%2F-MJWXuWTTmlaF7gFpJkN%2Fwhentimerfires.png?alt=media\&token=5c8dd648-a158-4283-aa69-1f9d1cd9438f)

Set something to happen when the Timer fires.

### Functions

#### Start Timer

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY4-Gx3BWY9BSWsUzhb%2F-MY43RwJkchmGugr63KZ%2Ftimst.png?alt=media\&token=63277dfc-69cc-4845-b86b-b7f5014a7850)

Starts the Timer.

#### Stop Timer

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY4-Gx3BWY9BSWsUzhb%2F-MY43XGibUJ5OIFfOEJw%2Ftimstop.png?alt=media\&token=fbacef3e-fb89-43e3-83cc-d7d54de12deb)

Stops the Timer.

### Property Blocks

#### Get time in seconds

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY43err2AVa2sp-xewX%2F-MY43jwC_eia5lxCHWKf%2Fgets.png?alt=media\&token=8e8963d7-d134-4ab8-93ed-c2b454e5bcf9)

If `Count Up` is `false`, returns remaining time from the Timer's interval in seconds.

If `Count Up` is `true`, returns elapsed time from the Timer's interval in seconds.

#### Get time in milliseconds

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY43err2AVa2sp-xewX%2F-MY43ocpgfnYLfCCYOyO%2Fgetms.png?alt=media\&token=de2078ee-b184-440a-90a7-638bf9d792ef)

If `Count Up` is `false`, returns remaining time from the Timer's interval in milliseconds.

If `Count Up` is `true`, returns elapsed time from the Timer's interval in milliseconds.

#### Set Interval

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY43err2AVa2sp-xewX%2F-MY43ydfIG3CSj7lRik4%2Fsetint.png?alt=media\&token=99c19bd9-add5-42f5-bd36-1bef767a9728)

Set interval of Timer in milliseconds.

#### Get Interval of Timer

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY43err2AVa2sp-xewX%2F-MY4438Wtt804U68oYSx%2Fgetint.png?alt=media\&token=e9b2d70c-caaa-4f4e-9baa-392ffb89dbfc)

Returns interval of Timer in milliseconds

#### Set Count Up

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY43err2AVa2sp-xewX%2F-MY448qTmgO6zepg_4M8%2Fsetcount.png?alt=media\&token=e4fa8eec-6d04-4880-928e-35533004e283)

Set whether Count Up is enabled for this Timer.

#### Get Count Up

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY43err2AVa2sp-xewX%2F-MY44DnV5tRBKRUDq1rd%2Fgetcount.png?alt=media\&token=69bec6dd-4fb3-4092-afc7-489f782d5e59)

Returns `true` or `false` value for whether Count Up is enabled for this Timer.

#### Set Loops

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY43err2AVa2sp-xewX%2F-MY44Iy7A0Y6Qu9-wePN%2Fsetloops.png?alt=media\&token=95e2e6c1-4575-4692-af67-bb2d2367b866)

\
If `Loops = true`, the timer will reset itself after it fires. If your interval is 10 seconds, the Timer will fire every 10 seconds.‌

If `Loops = false`, the timer will finish its current interval if it is in the middle of one, and will no longer fire. If your interval is 10s, the timer will finish its current 10 second interval, fire, and then stop.

#### Get Loops

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY43err2AVa2sp-xewX%2F-MY44OMtq-ROtnppYkIi%2Fgetloops.png?alt=media\&token=15cda444-1c4b-4407-962c-2b6142ab4a7d)

Returns `true` or `false` value for whether Loops is enabled for this Timer.

#### Set Enabled

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY43err2AVa2sp-xewX%2F-MY44Uj-q5iFOtdww4s0%2Fsetenabled.png?alt=media\&token=584afc89-4266-496e-8504-f0dfd09efe39)

Set whether the Timer is enabled.

#### Get Enabled

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MY43err2AVa2sp-xewX%2F-MY44cDFzmYJvAMZpwp9%2FScreen%20Shot%202021-04-12%20at%208.52.24%20AM.png?alt=media\&token=0733368c-db30-4c08-9c3b-eaa4ca8e1473)

Returns `true` or `false` value for whether this Timer is enabled.

### Example 1: **How to Build a Stopwatch**

1. Start by creating a variable and set its value to 0 (this will keep track of the time).
2. Add a timer to your project.
3. Add a button that will start and pause the stopwatch.
4. Inside the "when button click" block, add a condition: if the timer is running, pause the stopwatch; if it's not, start it.
5. Set the timer interval to 1 second/1000 Milliseconds and enable looping so it keeps running.
6. Add a label to display the elapsed time in seconds.
7. Use the "when timer fires" block to increase the variable by 1 every second and update the label with the new value.

<figure><img src="https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LAn5scXl2uqUJUOqkJo-84897653%2Fuploads%2FPYjNq0QgTISZm0Jrblpq%2Fimage.png?alt=media&#x26;token=4da1bc67-8ebc-4093-aa0e-962a06c05707" alt=""><figcaption></figcaption></figure>

### Example 2: **How to Build a Timer**

* Start by creating a variable and set its value to 5000 to count five minutes.
* Add a timer to your project.
* Add a button that will start and pause the Timer.
* Inside the "when button click" block, add a condition: if the timer is running, pause the Timer; if it's not, start it.
* Set the timer interval to 1 second/1000 Milliseconds and enable looping so it keeps running.
* Add a label to display the running time in seconds.
* Use the "when timer fires" block to decrease the variable by 1 every second and update the label with the new value if the variable is greater than zero.

<figure><img src="https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LAn5scXl2uqUJUOqkJo-84897653%2Fuploads%2FSJ5UmbVTnG0ephNwPzM8%2Fimage.png?alt=media&#x26;token=c2e2fac1-7d08-4d75-804a-3856a7ee310e" alt=""><figcaption></figcaption></figure>
