looping timelines with button responses. #2006
-
I have seen this - https://www.jspsych.org/overview/timeline/#looping-timelines - on JsPsych but it uses the comparekeys function. how do i loop timelines when my experiment uses button responses? I also am having trouble looping one particular stimulus. the code for this block looks like this: var POD_stimuli = [
{stimulus: 'BucketThere_POD.wav'},
{stimulus: 'BuckleWhich1_POD.wav'},
{stimulus: 'GarbageWhere_POD.wav'},
{stimulus: 'GarlicThere2_POD.wav'},
{stimulus: 'MarbleWhere1_POD.wav'},
{stimulus: 'MarkerWhere_POD.wav'},
{stimulus: 'PeacockThere2_POD.wav'},
{stimulus: 'PeanutThere2_POD.wav'},
{stimulus: 'TurkeyWhich2_POD.wav'},
{stimulus: 'TurtleWhere2_POD.wav'}
];
var POD_trials = {
timeline: [
{
type: 'audio-button-response',
stimulus: jsPsych.timelineVariable('stimulus'),
choices: ['OK', 'Listen again'],
post_trial_gap: 500,
},
{
type: 'html-button-response',
stimulus: ["Tell your experimenter what word she was about to say, or listen to the recording again!"],
choices: ["Continue", Listen again],
post_trial_gap: 500
},
]}
var POD_loop_node = {
timeline: [POD_trials],
loop_function: function(data){
if(jsPsych.pluginAPI.compareKeys(data.values()[0].response, '1')){
return true;
} else {
return false;
}
}
}
var POD_procedure = {
timeline: [POD_loop_node],
timeline_variables: POD_stimuli,
repetitions: 1,
randomize_order: true
} Again, I just want one stimulus to repeat, not the whole block. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @rbruno1, you're right that the Also, your loop_function: function(data){
if(data.values()[1].response == 1){
return true;
} else {
return false;
}
} Tip: if you're not sure how to extract the information you need from the data in the loop function, you can always print the data out to the console so that you can see what it looks like after each loop: loop_function: function(data){
console.log(data.values());
if(data.values()[1].response == 1){
// etc. But I noticed that with this solution, the loop function is only checking the value of the 2nd button press to determine whether to loop over the two trials, which means that pressing the 'Listen again' button during the first (audio) trial won't actually do anything. You could check the button presses on both trials in the loop function, and loop over the two trials if either one was pressed (i.e. var POD_loop_1 = {
timeline: [{
type: 'html-button-response',
stimulus: jsPsych.timelineVariable('stimulus'),
choices: ['OK', 'Listen again'],
post_trial_gap: 500
}],
loop_function: function(data){
if(data.values()[0].response == 1){
return true;
} else {
return false;
}
}
};
var POD_loop_2 = {
timeline: [{
type: 'html-button-response',
stimulus: "Tell your experimenter what word she was about to say, or listen to the recording again!",
choices: ["Continue", "Listen again"],
post_trial_gap: 500
}],
loop_function: function(data){
if(data.values()[0].response == 1){
return true;
} else {
return false;
}
}
}
var POD_procedure = {
timeline: [POD_loop_1, POD_loop_2],
timeline_variables: POD_stimuli,
randomize_order: true
}; Note that now you'd be using |
Beta Was this translation helpful? Give feedback.
Hi @rbruno1, you're right that the
compareKeys
function is just for comparing key presses. To compare a button press response, you can just use the double-equals operator to test if they're the same. Button press responses are stored as numbers in the jsPsych data, so probably best to compare against the number 1 (instead of the '1' string).Also, your
POD_loop_node
timeline contains two trials, so the data that's passed to theloop_function
parameter will contain the data from both of those trials. I think your goal is to check the button response from the second trial in the timeline? If so, then you want to index the second set of trial data inside ofdata.values()
, which means you'll …