-
Hello, I'm trying to implement a while loop so that I can have a trial repeats until the participants satisfy the criteria. I'd like to have the participants be prompted when they did not meet the criterion. So far what I got is: In my main HTML file: var while_loop_horizon_practice = {
timeline: [trial_I_repeat], // this is the trial, it worked pretty fine on it own
loop_function: function(){
var data = jsPsych.data.get().last(1).values()[0];
if(data.passed == false){ // the passed feature is set to "false" when the certain criteria are not met
return true; // so the trial would remain in the loop
} else {
return false;
}}
} And in my plugin file, the part where I found particularly buggy is when I deal with the end of the trial: if (num_in_frame == trial.stimuli.length ){ // this is where I checked whether it meets the criteria
trial_data.passed = true;
display_element.innerHTML = '';
jsPsych.pluginAPI.clearAllTimeouts();
jsPsych.finishTrial(trial_data); // this block works pretty fine with the for loop. It breaks the while loop and proceeds to the next trials
} else { // but this block doesn't work as expected
trial_data.passed = false; // I set this to be false, so it stayed in the while loop forever
display_element.innerHTML = '??????'; // ideally this would give the participants a prompt, but this prompt never showed up
jsPsych.pluginAPI.setTimeout(jsPsych.finishTrial(trial_data),200); // I was hoping to achieve: showing the prompt 2s, then repeat the trial. But right now the prompt didn't show up, and it just repeated the trial
} I wonder if I misunderstand the logic of terminating the trial or while loop. Any suggestion would be deeply appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
In your The first is that the first parameter to setTimeout should be function. At first glance it looks like you are passing a function, but you are actually calling the The second is that your timeout value is 200ms instead of 2,000ms. Try this instead: jsPsych.pluginAPI.setTimeout(function(){ jsPsych.finishTrial(trial_data) },2000); |
Beta Was this translation helpful? Give feedback.
In your
else
block there are two issues with thesetTimeout
method.The first is that the first parameter to setTimeout should be function. At first glance it looks like you are passing a function, but you are actually calling the
finishTrial()
function and using the value of that function as the argument.The second is that your timeout value is 200ms instead of 2,000ms.
Try this instead: