I uploaded an experiment that I have in PsychoPy onto pavlovia last night (link), and everything seems ok until I try to run it and I get the following message. Is there an issue presenting image files?
Message:
Unfortunately we encountered an error:
when setting the image of ImageStim: ANT_instr_img
when getting the value of resource: C:\Users\L\Documents\PsychoPy\MemANT\ANT_instructions.png
unknown resource
Try to run the experiment again. If the error persists, contact the experimenter.
You’ve set your image file to have the path: C:\Users\L\Documents\PsychoPy\MemANT\ANT_instructions.png
That doesn’t exist on the web (or indeed if you move your experiment to a different folder on the local computer).
Always set your images to have a path relative to the experiment (in this case just the image path should just be ANT_instructions.png)
This is how I always work with standalone PsychoPy experiments, but there must be something I’m missing for pavlovia implementations because I’m getting the same error as the OP.
Using a relative path in the .psyexp (e.g., stimuli/image.png) and exporting to html, the stimuli end up inside a resources directory, but the .js maintains the stimuli/image.png path and altering that to resources/stimuli/image.png doesn’t work either. What am I missing and/or doing horrifically wrong here?
Thanks for getting back to me about this, Jon. That structure looks familiar and similar, but not identical: my conditions.xlsx file is not in the /stimuli directory, just in the /resources one. Could that be the issue?
This is one of the projects I’m having this issue with: https://gitlab.pavlovia.org/PsyTechMMU/pavloviatest
(if that’s the link you meant - apologies if not: despite the way many would describe me, I’m quite new to the world of git)
My single image file in Ebbinghaus Darts is giving an unknown resource error in the local debug mode, but not via Pavlovi. The file is in the experiment root folder plus html/resources. It isn’t referenced in the code snippet, just in a builder component.
Gary, sorry, yes the conditions file outside the folder (I’ve edited my post to reflect that).
I just copied yours with no changes and the image loading worked fine, so not sure why yours went wrong. sometimes though it’s a cache thing - if you updated the experiment (initially failed to include the image file) and then try to run, the javascript/html/resources from the first attempt get cached by your browser and then your changes aren’t reflected even though they have made it to the server! Try a Shift-R to reload and fully refresh the cache on the browser.
BUT although I get the images to load fine I got stuck on your liberal use of random and randint. random() need to be converted to use Math.random in the JS code and that autotranslation clearly isn’t working. Similarly randint needs to be converted to a function that we should define at the top of the script but that currenlty has to be added separately (I think we’ll be doing this one automatically in next release). You can add the necessary code like this:
Add a code component to one of your initial screens (eg. instructs) and create a code component that’s pure JS (not auto-trans). In the Begin Experiment add this code:
// alias for random func
random = Math.random
// also define randint
function randint(min, max) {
return Math.floor(Math.random() * (max - min) ) + min;
}
and then your randint (and random) functions will work again
Apologies for the delayed response, but thank you so much for all this assistance. The random stuff (so “liberal” just because the experiment is intended as just a demo) was something I’d been grappling with and was in the process of trying to implement as Math.random JS, so your confirmation that this is what I need to do (and the functions!) are greatly appreciated. Thank you!
Unfortunately, however, after adding the function code you provided (in the Begin Experiment tab of a pure JS, not auto-JS Code component right at the beginning of the experiment) I now get:
No, this looks like a failure to define the function with the correct scope (e.g. it is being defined only for the BeginRoutine section of code rather than the whole script. Less efficient, you could add it to the code where it’s needed instead (was it on Begin Routine?)
In the next release I’ll make sure these functions are defined at the top of the script so you won’t need to define them at all
Ah, right. Yes, that seems to be it and it appears to work now. Thanks again!
Alas, I now get as far as the yesno routine, which is set to respond to y or n keys and end the loop accordingly, but I get an error about length. It looks (to me) like the auto-JS code isn’t correct for this and maybe ynResp.keys.length should be Object.keys(ynResp).length:
Someone suggested that the issue is that the yResp.keys is initialised to undefined in the JS code, not null.
For the Code Component where this isn’t working, could you switch from Auto to Both so that you can manually set the code and set it to:
Thanks again, Jon. Happily, it no longer errors out, but it also doesn’t work either… What I mean is that pressing keys (specifically, y or n) doesn’t exit the loop, the loop just plays out (via Pavlovia, it works fine as it did via PsychoPy).
Sidenote: is it expected for the Code component to automatically revert to Auto after being set to Both? As instructed, I set it to Both before amending the JS code, but when going back to it, it’s back to Auto…