TypeError: psychoJS.downloadResources is not a function

Not sure if this is still an issue, but I managed to get this working for my own experiment.

Using the same JavaScript code component that determines the participant’s stimuli list .csv file based on their participant number, during “Begin Experiment”, I extracted the file names of the stimulus images from that file using code based on
this forum post. Within the successFunction(), which I renamed to get_filenames(), I extracted only the column containing the filepath and added it to a predefined array to contain the additional resources. So the inside of the for-loop looked something like this:

file_path = allRows[i].split(‘,’)[fp_column];
add_resources.push({‘name’: file_path, ‘path’: file_path});

I previously extracted the file name and tried treating that differently, but was running into some bugs doing it that way, plus when you add additional resources through Options>Online, it gets formatted in the experiments javascript file with the name and path both being the relative file path including the file name.

Also, my experiment reuses stimulus images dependent on the within-subject condition so I only had to iterate through half of the stimulus file.

Anyway, most importantly, I dug through the documentation and found the function that downloads additional resources to be:

psychoJS._serverManager.prepareResources(add_resources);

If you want to make sure the experiment loads all of the files before beginning the experiment then you can add “wait” to proceed the above function call. However, using this method, if there is preliminary information like informed consent or instructions before the stimulus is used, it should be able to download their files in order and faster than they can go through them. But, if you are using a random loopType, I would recommend reformatting the stimulus files to introduce randomness (maybe having multiple versions in different orders) or would use the “wait” modifier in case the last file loaded is the first file used.

I also found that this worked whether I loaded the resources via the traditional method, or whether I initialized add_resources with the copied initialization from the traditional method’s experiment javascript file before removing them from the Options>Online>Additional Resources box (that way I can get all the condition consistent resources formatted without having to do much work).

Either way, this forum post pointed me in the right direction to figure this out so thanks for positing it, and I hope this helps someone :slight_smile:

2 Likes