# Timer does not terminate(?) if variable is specified in units of ms; behavior as expected if no units supplied

**URL:** <https://mworks.discourse.group/t/timer-does-not-terminate-if-variable-is-specified-in-units-of-ms-behavior-as-expected-if-no-units-supplied/210>\
**Category:** Support\
**Created:** [January 10, 2020, 4:19pm UTC](https://mworks.discourse.group/t/timer-does-not-terminate-if-variable-is-specified-in-units-of-ms-behavior-as-expected-if-no-units-supplied/210 "2020-01-10T16:19:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [January 10, 2020, 4:19pm UTC](https://mworks.discourse.group/t/timer-does-not-terminate-if-variable-is-specified-in-units-of-ms-behavior-as-expected-if-no-units-supplied/210/1 "2020-01-10T16:19:37Z")

</div>

Hey Chris,

In our MTS experiment, we have a “punish” timer that is triggered when the subject makes an incorrect choice. We specify the duration of the timeout using a variable

```
var punish_duration_ms = 500
var intertrial_interval_duration_ms = 0

```

which is then used later on here:

```
if (failure == 1) {
                        start_timer (
                            timer = MyTimer
                            duration = punish_duration_ms+intertrial_interval_duration_ms
                            duration_units = ms
                            )
                        if (test_image_location_index == 0) {
                            start_timer (
                                timer = MyTimer
                                duration = punish_duration_ms+intertrial_interval_duration_ms+punish_duration_ms
                                duration_units = ms
                                )
                        }
                    }

```

This works as expected. However, originally we had specified `var punish_duration_ms = 500ms` (note the units), and this lead to a timeout that does not terminate (at least over the time I observed it; ~ 2 minutes).

Is this expected behavior, or is this possibly a bug?

Michael

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [January 10, 2020, 4:58pm UTC](https://mworks.discourse.group/t/timer-does-not-terminate-if-variable-is-specified-in-units-of-ms-behavior-as-expected-if-no-units-supplied/210/2 "2020-01-10T16:58:57Z")

</div>

Hi Michael,

> However, originally we had specified `var punish_duration_ms = 500ms` (note the units), and this lead to a timeout that does not terminate (at least over the time I observed it; ~ 2 minutes).

MWorks’ [unit operators](https://mworks.github.io/documentation/latest/expressions/index.html#units) are very simple: They just multiply the expression that proceeds them by a constant (1000 in the case of `ms`). Hence, the expression `500ms` evaluates to 500000. If you then use this value as the duration in a `start_timer` action whose `duration_units` parameter is set to `ms`, you’ll get a timer duration of 500000ms (i.e. 500s or 8.33 minutes).

If you want to initialize your duration variable with the expression `500ms`, then you should omit `duration_units` from the `start_timer` action. (The default value is `us`, which is what you want.) In that case, I’d also recommend not including the “\_ms” suffix on the variable name, since the value will actually be in microseconds.

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [January 10, 2020, 5:06pm UTC](https://mworks.discourse.group/t/timer-does-not-terminate-if-variable-is-specified-in-units-of-ms-behavior-as-expected-if-no-units-supplied/210/3 "2020-01-10T17:06:59Z")

</div>

Makes sense! Thanks Chris.

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 8:37pm UTC](https://mworks.discourse.group/t/timer-does-not-terminate-if-variable-is-specified-in-units-of-ms-behavior-as-expected-if-no-units-supplied/210/4 "2022-07-19T20:37:12Z")

</div>

Closed on July 19, 2022, 8:37pm UTC


