Accessing jsPsych.timelineVariable() in the conditional_function() #2022
-
Hello everyone, I am currently programming an experiment where I want to repeat specific trials in a random order at the end of the timeline. How can I check a timeline variable of the upcoming trial in the conditional_function()? Thanks for your help! DUMMY CODE: trial = { feedback = { trial_conditional = { feedback_conditional = { my_experiment = { |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @ClaraKuper, not sure if this is the best solution, but I think it works: var timeline_variables = [
{ID: 'trial 1'},
{ID: 'trial 2'},
{ID: 'trial 3'}
];
var repeat_IDs = []; // holds list of IDs to repeat on the next round
var first_set = true; // whether or not this is the first presentation of trials
var trial = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('ID'),
choices: jsPsych.ALL_KEYS,
trial_duration: 2000,
on_finish: function (data) {
if (data.response == null) {
if (!repeat_IDs.includes(jsPsych.timelineVariable('ID'))) {
repeat_IDs.push(jsPsych.timelineVariable('ID'));
}
} else {
repeat_IDs = repeat_IDs.filter(function(item) {
return item !== jsPsych.timelineVariable('ID');
});
}
}
}
var feedback = {
type: 'html-keyboard-response',
stimulus: 'feedback',
trial_duration: 1000
}
var trial_conditional = {
timeline: [trial, feedback],
conditional_function: function() {
if (first_set || repeat_IDs.includes(jsPsych.timelineVariable('ID'))) {
return true;
} else {
return false;
}
}
}
var my_experiment = {
timeline: [trial_conditional],
timeline_variables: timeline_variables,
loop_function: function () {
first_set = false;
return repeat_IDs.length > 0;
}
} The thing that initially made this tricky was having separate conditional nodes for the trial and feedback, because the Let us know if this works for you, and if you have any questions. |
Beta Was this translation helpful? Give feedback.
Hi @ClaraKuper, not sure if this is the best solution, but I think it works: