Pavlovia: Can't find Psychopy setImage and core.getTime functions

Hi everyone,

I’m currently trying to get my experiment to run online.

I ran into a few problems because PsychoJS doesn’t “know” the randint() and shuffle() functions from Python’s random package, but I solved this by adding snippets of JS code with equivalent functions.

Now I’m facing the same problem with the setImage() and core.getTime() functions and I don’t really know how to fix this.

Does anyone know how I could implement equivalent functions or import JS packages that work like the Python ones?
It would be super helpful if anyone could give me a hint! Thanks in advance for your help!

@wakecarter has put together an excellent guide for exactly this purpose: PsychoPy Python to Javascript crib sheet

3 Likes

Ooh thank you, I didn’t know this sheet existed! :blush:

I fixed a few things I found in the document and now I don’t get the error message for setImage() anymore, but unfortunately, the images can’t be shown anyway.

In my experiment, I’d like to randomly assign one of two conditions. I do this by creating a random bit and if it’s 0, the participant gets instruction image 1, and if it’s 1, they get instruction image 2.

This is my code (btw: I know, weird approach to get the random bit):

# get random bit
choose_condition = shuffle([1,0])
# choose right instruction sheet
if choose_condition[0] == 0:
    instr_condition = "Bilder_Bedingungen/Instruktion/cond1.png"
else:
    instr_condition = "Bilder_Bedingungen/Instruktion/cond2.png"
  

And then I set the image path as $instr_condition

The code seems to work, at least it generates the correct path and I don’t get an error message anymore, but as I already mentioned, the image doesn’t appear on screen and if I have a look at the developer tools in my Browser, I get the following warning: “the Pixi.js representation of this stimulus is undefined”.

I tried clearing the browser cache, but the problem persists.

Does anyone have an idea what this means and how I can fix it? I’m afraid I don’t really have a clue what’s happening there.

Try putting Bilder_Bedingungen/Instruktion/cond1.png as the image to see if that works.

If so, then you probably need to add the resources in Experiment Settings / Online

If not, then the issue is probably with your image file, or its path or its capitalisation

1 Like

Thanks so much for your quick reply!

I tried putting the path as the image and it worked perfectly, so I added the resources in the settings as you said. The thing is, when I changed the path back to my variable again, it didn’t work anymore.

I triple-checked if the images are all in the HTML file (they’re definitely there) & the names are also correct. I tried changing the path and the capitalization then, as you said, and I also updated Psychopy, but that didn’t do the trick either.

Is there maybe anything else I could try to make this work?

What version of PsychoPy are you using?

I just upgraded to v2021.1.4, before I had v2021.1.2.