What’s the correct way to do csv-based image stimuli on Pavlovia?
We are starting a MST implementation that needs to display images from pre-selected random orders, so we have the ImageStim pull from $image_filename every repeat, and a code element that runs at Begin Routine sets that path.
This works fine running in Python, but on the JS side we get "Unfortunately we encountered an error: when setting the image of ImageStim: image … when getting the value of resource: stimulus_sets/set_1/1.jpg: unknown resource
So the JS side is setting the correct path, but the resource is not getting preloaded because the preload pipeline doesn’t know about it.
How to fix this? Do we need to add code to iterate over the possible stimuli and preload them into the resources? I’m not sure I understand how the backend for that works, yet.
Hi @dgfitch, the problem is that your stimuli are defined using a code component, so those stim are not actually recognised as a resource needed for the task and so are not copied to the html/resource folder for use in the task. To overcome this issue, copy the stim folders into the resource directory in your html folder, and sync with Pavlovia.
This sort of issue will not occur in the future, when we flatten out the directory structure and remove the need for a separate html/resources folder containing duplicate resources.
Hmm, okay… when I put the images in html/resources manually, they do preload.
However, the conditions on the trial seem to be loaded differently. In the python side, the CSV defines the stimuli as “001a” or the like. On the JS side, when I log it, the CSV value is set to “1”, so the eventual resource path ends up being “stimulus_sets/set_1/1.jpg” instead of “stimulus_sets/set_1/001a.jpg”, and I still get the “unknown resource” error.
@dgfitch, yes the issue there is that PsychoJs will treat things that look like numbers as numbers. A way around this is to add a letter to the beginning of your file variable in your conditions file so it is recognised as a string, e.g., a001b. Then, slice it off just before you create your filename. E.g.,
Yes @njvack, that is simpler, but then you have to rename all of your files. I have requested a fix that checks for characters in any number strings, and does not convert to number if any characters are found. This should solve the issue, and should be released in 3.1.3.
With the current fix (which is not yet implemented by Alain, so could change), any number without characters is treated as a number, otherwise it is treated as a string. So, 001 == 1, 0.1 == 0.1, and 01a == '01a'.