Cannot read property 0 of undefined

URL of experiment:

Description of the problem:
I want to shuffle some sound stimuli and congruency information.
As it is not possible to access an excel file with xlrd, I created two lists (one for the sound stimuli and one with the congruency information). When running the experiment, I get the error “cannot read property 0 of undefined”. I read some threads and tried to remove “var”, but then I get the error that i is not defined. I also read the python --> javascript crib sheet and specified shuffle (shuffle = util.shuffle), but the error persists. I would be happy about any idea why this might happen?

Hi There,

A couple of things that could help here.

  1. Please could you set your pavlovia project to public so that we can view it (details on that here

  2. Please could you open the developer tools when you reach this error, and click on the red message with the name of your experiment in the developer panel (see ‘finding the problem’ in the URL shared). That will take you to the exact line in your experiment where this is occurring. If you can share with us the exact code segment causing the issue that will also be helpful so we can figure out how to tackle the issue :slight_smile:


Dear Becca,
Thanks a lot for your reply!
I set the experiment to public.
When I open the developer tools, I get several error messages…

Screenshot 2020-12-23 at 09.30.20|578x232

However, I think that the problem is probably in line 490, which is:
for (const thisTrial of trials) {
I guess that there is a problem with the loop…

Thanks again!

Hi again!
I still could not solve the problem and wanted to ask again whether anyone has any idea?
I would be happy about any suggestions!

If the problem is with the loop, please could you show a screenshot of your loop. There might be a problem with your nReps or userows.

Thanks for your reply!

This is a screenshot with the loop in it, (because the excel import did not work in javascript, I created two lists, in which I listed all of the stimuli). I reckon that the mistake is somewhere in the for loop, in which the order of the symbols is shuffled.

Why are you starting from row 1 instead of 0 ?

I think this is how psychopy builder started counting? Unfortunately it is not my code, but I was asked to try to make it run online…

Screenshot 2020-12-29 at 08.48.21

This is the code from the javascript html file (line 490 is where the error appears), maybe this is more helpful?

I’ve just had a look at your experiment and codeInit as imports in the JS (which won’t work) and a syntax error.

Also, in the trials loop, I think you should remove the $ from num_items.

The reason for the error is because your code translations aren’t working. Have a look at my crib sheet (see pinned post) but you will need someone who at least understands the Python code in your experiment.

Thanks again for your reply!