Pavlovia- Randchoice is not defined

URL of experiment: Pavlovia

Description of the problem:

Heya,
I’m trying to launch my experiment online but I don’t get very far.
I’m getting this error message:
“ReferenceError: randchoice is not defined”

I do use randchoice in my code but I’m not sure if I need to substitute it with something else. I’m a bit lost :confused:

I’m grateful for any help! Thanks in advance.

Margo

Hello IcedMargo,

I assume that the experiment runs offline. Did you use import random? Do you use the Builder to program your experiment? The Builder imports all libraries for which there is a PsychoJS-equivalent, so there is no need to explicitly import python-libraries which wouldn’t run online anyway.

BTW, it is rand.choice() not randchoice() as you wrote.

Instead of using rand.choice, you could shuffle the list and select the first element of the list.

Best wishes Jens

In a Builder experiment, randchoice is fine as we import numpy.random.choice as randchoice at the top of the Builder script (this is because for choice in choices is a pretty common line to find in :code: Code components so calling it randchoice is a bit safer).

It looks like, although there is a PsychoJS equivalent of randchoice, it’s not translated properly. I’ll fix this for the next release, until then you can set your :code: Code component to be “both” rather than “auto->JS” and anywhere you’ve used randchoice, instead use util.randchoice

Thank you very much! I’ve tried a lot of things and this helped me a lot.