Timer for experiment #3230
miriamhavin
started this conversation in
General
Replies: 1 comment
-
I gather you have a timeline and a timer; you want the timeline to finish when the timer ends, but as you are also using timeline variables which end up inserting multiple trials in the child timeline, you want the timer to start only once before all trials and to end all trials once and for all. If I have presumed correctly, an example piece of code is provided below. let timer; // global variable to store the timer
let trial = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
timeline_variables: [
{ stim: 1 },
{ stim: 2 },
{ stim: 3 },
{ stim: 4 },
{ stim: 5 },
{ stim: 6 },
{ stim: 7 },
{ stim: 8 },
{ stim: 9 },
{ stim: 10 },
],
timeline: [
{
stimulus: jsPsych.timelineVariable('stim'),
}
],
on_timeline_start: function () {
timer = setTimeout(function () {
// Note that endCurrentTimeline has to wait until the current trial is over. So, if we call `finishTrial`
// prior to `endCurrentTimeline`, it will proceed to the next trial first and hang there.
//
// It is also due to this nature of `endCurrentTimeline` that we do not need to check whether this is the
// last trial in the timeline.
jsPsych.endCurrentTimeline();
// TODO: fill it with data you might want to store for the last unfinished trial
jsPsych.finishTrial({response: null});
}, 3000);
},
on_timeline_finish: function () {
clearTimeout(timer);
}
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I want to add a timer that will run throughout a trial and will automatically move to next when timer is over. Trial has several timeline variables and I want the timer to continue throughout without restarting with every variable.
Beta Was this translation helpful? Give feedback.
All reactions