TypeError: psychoJS.downloadResources is not a function

URL of experiment:

Description of the problem:
Hi there :slight_smile:
I would like to download images on the fly, and psychoJS.downloadResources was working well a while ago. I’ve tried running it again recently, but now I get: * TypeError: psychoJS.downloadResources is not a function on Pavlovia.

I don’t know whether I should look for mistakes in my code or call downloadResources differently/use another approach. Could anyone help?

Thanks

I got this recently. I think that the issue is that PsychoPy now lets you start the experiment before all resources are downloaded. Resource downloading via Experiment Settings / Online may therefore now conflict with downloading in code.

Does this sound logical @TParsons ?

1 Like

Thanks, @wakecarter. Would it be a permanent/long-term thing, then? Do you know of any other way around it?

If this is the issue then the way forward might be to download all resources via code or none.

1 Like

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

Hi @cffitzgi ! Thanks for your explanation. I’m encountering a similar issue as OP, where I’m loading audio files and when I get to the Routine with the pyschoJS.downloadResources, I get the error OP mentioned. Importantly, this error did not happen previous to downloading the new version. (wakecarter actually helped me debug this experiment, so I’m working with their code structure)

Could you provide an example of how to add “wait” code to the function call you provide to mitigate the issue?

Similarly, if I instruct use an older version of PsychoPy via Properties > Basic, will this mitigate the issue when uploading to Pavlovia?