Hi Michael,
Minor point: It’s best to think of resources('images')
as a declaration, i.e. a note to MWorks saying “these files need to be copied to the server”, rather than as code that runs.
Does calling resources(‘images’) indeed copy all files contained within to the server (overwriting existing files?)?
Yes.
If so, is it then not recommended to call resources on a directory containing many files, even if only a select few files will be referenced (e.g. as image_file components)?
Copying more files means your experiment will load more slowly, as all the files are sent over the network at load time. But MWorks doesn’t care if you use the files or not, so I can’t say that it’s “not recommended”.
Related question: why is it necessary to run resources(‘images’) prior to creating image_file components from paths inside of images/?
It doesn’t matter where in the experiment you put that line. For instance, in this example, resource ('images')
could be the last line in the MWEL file, and everything would work fine.
When I wrote the comment
// Need to declare the "images" directory as a resource in order to use an expression
// for the image stimulus' "path" attribute
I wasn’t trying to say that you needed the resource declaration right there, just that you need to include it somewhere for the example to work. If you omit it, the experiment will fail to load with the error:
Experiment packaging failed: Unknown variable: image_paths
To be clear, not all experiments require resource declarations. However, this particular example does require one, because the “path” attribute of the image_file stimulus is an expression instead of a literal path. That said, my feeling is that all new experiments should use resource declarations, as they make the experiment’s dependencies explicit and enable some things that aren’t possible otherwise.
Cheers,
Chris