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

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

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

Makes sense! Thanks Chris.