Online Study run into error: TypeError: Cannot read property '0' of undefined


I am running a study online that includes multiple tasks. As I am doing the piloting and finishing the first task, I ran into the following error: TypeError: Cannot read property ‘0’ of undefined.

The task run fine offline, I am not sure what is going on that causes the error. I would appreciate any help. Thank you!

Hi There,

Have you tried opening up developer tools to get some hints where the problem could be occuring?

See the crib sheet for how to open developer tools of different browsers PsychoPy Python to Javascript crib sheet - Google Docs

See this page for a step-by-step how to debug these types of errors in pavlovia Creating online studies from Builder — PsychoPy v2020.2

A common cause for this error could be if a field is left totally blank but is needed in JS

Hope this helps as a start point!


1 Like

Thank you for the resource!

Hi Becca,

I think the error was caused by the repeat time of a routine set to be 0. For my experiment, I was trying to counterbalance the order of tasks and I followed the instruction for counterbalancing subtasks in builder and convert the experiment online.
It seems like that I cannot use the same method for online experiments. I am wondering if you have any clue for how to counterbalance subtasks online. Thank you!

1 Like

Hi There,

That should work still online (it did when I checked on v 2020.2.10) - please can I check if we are on the same version?


1 Like

I just changed the version to the latest version. But I did upload the initial experiment using an older version, I will sync the experiment again and see if it solves the problem. Thank you so much for your help!

What do you mean by “repeat time”? If you mean nReps then that works online but should not have a $ in front of the variable name.

1 Like

That is probably why, somehow it runs fine without the offline and so I wrongfully assumed that it does not need '’ online. I am sorry for making such a stupid mistake. Thank you for your help!

I’m having a similar issue, can I not use nReps twice in a project? For example, if I have numEncoding = 25 for my encoding blocks, can I set numEncoding = 25 in a code component before the loop and use this for nReps, then set it numEncoding = 25 again in a different component before another loop and have it work? I’m now looking into whether using a different name would fix the problem, but I thought that since I was re-setting it it should work

You should be able to use the same variable twice.

I’m not sure why you would need to set it to 25 twice. When does it change?

I’m running a memory task with 2 blocks (different images in the blocks) and each block has 25 encoding and 40 retrieval trials. I didn’t make it a big loop because I was changing the images and didn’t know how to set the code for that, so I just made psychopy routines like encoding 1, encoding 2 etc. For these loops, I set the nReps to numEncoding, so telling it to run 25 trials for both blocks, however, when I’m piloting the study and get to the second block, I get the same error as in this question! I tried re-naming it to numEncoding2 but it didn’t help, I thought maybe it was giving me an error because it already ran 25 trials

Please could you show screenshots of your loops?

Of course, and also thank you very much for looking at this and helping out, I appreciate it a lot!

Thanks for showing your flow. Please could you show how your loops are defined (nReps selected rows etc)?

Yes! I define/assign numbers to them in the randomization routine then add to the nReps, and for the 2nd block of encoding and retrieval I do the same!

My project is also public if that is of any help!

@wakecarter I realized that I don’t get the error if I set the number lower. For piloting purposes, if I set numEncoding to 2 and numRetrieval to 4 in the first block, and do the same for the second block, I can run the whole task. However, when I set numEncoding to 25 and numRetrieval to 40 in both blocks, I get the error in the second block. If I keep numRetrieval 40 for the second block, but make numEncoding 3 or some lower number, then I can get through the second encoding block, but get the error after the encoding trials! Any idea why this may be? Is it because that it already ran the number of trials? I tried changing the names but that didn’t work for me