Problem with image file for pavlovia

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?

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.

Could you share a link to the actual experiment rather than a search address? Thanks


You’ve set your image file to have the path:
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)

I see! I assumed that because the file exists in the resources folder that this was enough. Thanks for the help

Hi @fffrost,

Have you been able to fix this problem? Would be able to help me how by explaining the process you did? I am facing similar problem that needs fixing.

Thanks in advance.

Hi @Shardul_Shankar, the solution is in the post above:

If that doesn’t work for you, could you start a new topic and post the exact details of your particular issue (including any error messages)?

Hi @Michael,

I have already created a similar topic which discusses my complete problem in detail here:

This might help you in understanding my problem better. Let me know if you need any further information.

Thanks in advance,

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?

hmm, not sure. This is the normal structure:


and in that arrangement, yes, the path stimuli/stim1.png should work fine. What’s the URL for the experiment on

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:
(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 :slight_smile:

Wakefield I don’t know the cause of your issue I’m afraid. I think the local debug mode needs more debugging! :confused:

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:

Something to do with me feeding it negative and positive values perhaps?

I get the same for images when using the local debug mode.

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. :frowning: 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! :smile:

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:

if (((ynResp.keys !== null) && (ynResp.keys.length > 0))) {
    flashingArrows.finished = 1;

Or, rather, I’ve not used the best Python code for it):

if ynResp.keys is not None and len(ynResp.keys)>0 :

Any ideas?

Excellent news! :blush:

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:

if (((ynResp.keys !== undefined) && (ynResp.keys.length > 0))) {
    flashingArrows.finished = 1;

If that works we can add it to the auto-convert tweaks we need to make :slight_smile:

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…

@PsyTechMMU, to end the loop, you have to use trials.finished = true;, rather than the name of the actual loop - see past GitHub issue

1 Like