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

mil's Avatar

mil

10 Jan, 2020 04:19 PM

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

  1. Support Staff 1 Posted by Christopher Sta... on 10 Jan, 2020 04:58 PM

    Christopher Stawarz's Avatar

    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 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

  2. 2 Posted by mil on 10 Jan, 2020 05:06 PM

    mil's Avatar

    Makes sense! Thanks Chris.

  3. Christopher Stawarz closed this discussion on 13 Jan, 2020 06:34 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac