manual progress bar for the Test block only

268 views
Skip to first unread message

Angela Xiaoxue He

unread,
Sep 10, 2018, 1:22:51 PM9/10/18
to jsPsych
I read the tutorial on progress bar here: https://www.jspsych.org/overview/progress-bar/.
The automatic bar seems to progress by block: intro block, practice block, test block, debrief block.
What if I want it to display only during the test block, and progress by each few test trials. Say, I have 300 test trials, and i want the bar to progress a little every 3 trials, something like that. 

I also read from the above tutorial that you can do some manual control, like the following:
var trial = {
    type: 'html-keyboard-response',
    stimulus: 'Almost done...',
    on_finish: function(){
        jsPsych.setProgressBar(0.85); // set progress bar to 85% full.
    }
}
However, my code for the test block is written like this (i'm using a 10-trial simplified version as an example):

var test_stimuli = [
    {stimulus: 'img/02-03.png'},
    {stimulus: 'img/02-04.png'},
    {stimulus: 'img/02-07.png'},
    {stimulus: 'img/02-08.png'},
    {stimulus: 'img/02-09.png'},
    {stimulus: 'img/02-12.png'},
    {stimulus: 'img/02-13.png'},
    {stimulus: 'img/02-14.png'},
    {stimulus: 'img/02-17.png'},
    {stimulus: 'img/02-18.png'},
    {stimulus: 'img/02-19.png'},
  ];
  var test = {
    type: 'image-keyboard-response',
    stimulus: jsPsych.timelineVariable('stimulus'),
    choices: ['f', 'j'],
    prompt: "<p><b>Which one is a better red?</b></p>",
  };

In this case, how should i write the code to achieve what i want? Thank you very much!

Josh de Leeuw

unread,
Sep 10, 2018, 4:33:26 PM9/10/18
to Angela Xiaoxue He, jsPsych
Unfortunately there is not a built-in function for showing or hiding the progress bar. You could add this on_finish event to the end of whatever trial you want to hide the progress bar after:

on_finish: function(){
  document.querySelector('#jspsych-progressbar-container').style.display = 'none';
}

To get the progress bar to tick after every few trials, you could do something like this:

var progress_bar = 0;
var tick_amount = 0.03;

 var test = {
    type: 'image-keyboard-response',
    stimulus: jsPsych.timelineVariable('stimulus'),
    choices: ['f', 'j'],
    prompt: "<p><b>Which one is a better red?</b></p>",
    on_finish: function() {
      progress_bar += tick_amount;
      jsPsych.setProgressBar(progress_bar);
    }
  };


--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To post to this group, send email to jsp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/655065b7-f515-4624-9c6c-b3105195fb83%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages