Conditional Function for Screening Two Trials #1930
-
Hello all, I have a task where participants only move to the main set of trials if they get at least 1 of 2 of the screener trials correct. I am trying to write a conditional function for this, but no matter how I try to debug it I can either get it to always go to main trial no matter the response, or the opposite (i.e., no one moves to the main trials no matter the response). I've not used conditionals for more than one trial before, and have tried using the suggestions provided here and here to no avail. I've copied a snippet of my code below. Any help is greatly appreciated! var voo_practice_b = {
type: 'html-button-response',
choices: ['Teacher','Minister','Lamp','Poet'],
prompt: '<p style="text-align: centre">'+
'Which word is the odd one out?<br><br> Please <b>click</b> on the word you think is correct.<br> If you are not sure, have a guess.',
stimulus: "", data: {test_part: 'VOO Screen', target: 'Lamp', correct_response: 2},
required: true,
response_ends_trial: true,
on_finish: function(data){
if(jsPsych.pluginAPI.compareKeys(data.button_pressed, 2)){
data.correct = true;
}
else {
data.correct = false;
}
}
var if_ab_errors = {
timeline: [voo_main], //should be displayed if at least 1 of 2 screens is correct
conditional_function: function(){
var counter = jsPsych.data.get().filter({test_part: 'VOO Screen', correct: true}).count();
if (counter => 1){
return true;
} else {
return false;
}
}
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi all - just an update on this, I was able to solve it! With jsPsych 6.3.1 button presses are now coded as data.response rather than data.button_pressed. Additionally, in my conditional function I needed to have separate filters for the filter tag for the trials I was using to screen for responses ({test_part: 'VOO Screen'}) and then for further counting the number of correct responses ({correct: true}). I have copied my code below in case anyone else has a similar issue.
|
Beta Was this translation helpful? Give feedback.
Hi all - just an update on this, I was able to solve it! With jsPsych 6.3.1 button presses are now coded as data.response rather than data.button_pressed. Additionally, in my conditional function I needed to have separate filters for the filter tag for the trials I was using to screen for responses ({test_part: 'VOO Screen'}) and then for further counting the number of correct responses ({correct: true}).
I have copied my code below in case anyone else has a similar issue.