Downloading resources on the fly
If you have a lot of resources then you might not want to download them all at the start of the experiment. If they aren’t too big, then you might even be able to download them during an ITI before each trial.
If your loop points at your conditions spreadsheet and your spreadsheet contains the full paths of your resources, then they may get downloaded automatically. You can stop this, either by changing the spreadsheet name into a variables or removing the folder names and/or file extensions from the resources.
To download one file at a time during an ITI, put the following code in Begin Routine in a JavaScript code component.
psychoJS._serverManager.prepareResources([
{ name: "images/" + imageFile, path: "images/" + imageFile },
]);
Note that the name and path are identical strings. In this case imageFile is the column name in my spreadsheet and the images are in a folder called “images”.
To ensure that the ITI doesn’t end too early (before the resource is available) but usually lasts for the intended ITI duration put the following in Each Frame
if ((t > .25) && (typeof psychoJS.serverManager.getResource("images/" + imageFile) !== "undefined")) {
continueRoutine = false; // Move to the next routine
}
The ITI routine will need a component with a blank duration. To run the same exaperiment locally, change the resource routine to Both and put the following on the Python side.
if t > .25:
continueRoutine = False
If you want to check what resources are currently available, use
console.log("Available resources:", psychoJS.serverManager._resources);
To download a list of resources at the same time (for example while the participant is reading instructions or doing hard coded practice trials) create a list of {name: resourcePath, path: resourcePath} dictionaries and use that list in prepareResources.