Streamlining downloading resources

Hey Adam,

Better support for dynamically downloading resources is high on the 2do list for PsychoJS, For the time being, I’m working on a kind of plugin that can do this for you. This is the current state of it:

  1. Works for images, not yet for spreadsheets (conditions)
  2. Still need to test it on multiple platforms; probably will do that in the coming two weeks.
  3. It uses rather funky programming concept, called a closure.

Having said this, below is some code that shows how it works. Create a routine that shows a text saying “One moment please…”, no end time, and add a code component with the script below.

This part goes into Begin Routine

var load = function(resources) {
  psychoJS.downloadResources(resources);
  return function() {
    // Check whether each resource is available
    try {
      for (var i = 0; i < resources.length; i++) {
        psychoJS.serverManager.getResource(resources[i].name);
      }
    } catch (e) {
      // Some resource not available yet; return true (continue routine)
      return true;
    }
    // All resources available; return false (end routine)
    return false;
  }
}
// StimA and StimB will be whatever image is specified via path
// You can use some code to change this per participant
window.checkProgress = load([
    {name: 'StimA', path: 'img/a.png'},
    {name: 'StimB', path: 'img/a.png'},
]);

This part goes into Each Frame

continueRoutine = window.checkProgress();