Error on Pavlovia: TypeError: cannot read properties of undefined (reading '0')

URL of experiment:

Description of the problem:
I have created a study in Psychopy using video stimuli.
But when I upload the experiment to Pavlovia, the experiment runs for a couple of seconds (showing two of the sets of videos) and then it crashes with the error: TypeError: Cannot read properties of undefined (reading ‘0’).

It seems to be happening on the second loop within the experiment (shown in image below). It seems to run the ‘observation’ loop once where the ‘obs_ran’ routine plays followed by the ‘obs_l’ and ‘obs_r’, but when it goes to do another rep of the whole observation loop it crashes.

Any help would be much appreciated.


Please copy the full text of the error message that pops up, and if possible please also get the text of the error message from the browser’s developer console (go to view or window → developer to find the console).

Screenshot 2023-06-06 at 11.59.08

OK. That means that it can’t read a property for the next trial. Can you share the loop settings for all four of the loops here? Observation, random_example, dots_obs_l and dots_obs_r?

Screenshot 2023-06-06 at 16.29.32
Screenshot 2023-06-06 at 16.29.43
Screenshot 2023-06-06 at 16.29.51
Screenshot 2023-06-06 at 16.29.58

I also have a code component defining dots_obs_l and dots_obs_r

First, try putting that code in the “before experiment” tab rather than the “begin experiment” tab. I don’t think that’s the main issue but just in case there are any scope problems it will help.

Otherwise, I’m not sure. It could be an issue with the “inner” loop (random_example) not being able to read the excel file again after the first run through it, but in principle I think that should still work. How is the “Routine” parameter used in obs_l and obs_r?

Hello Claire,

I just have a few comments about the structure of your experiment. My comments will not help you directly with the error message you get, but they may help you to simplify the flow of your experiment and make debugging easier.

  1. A loop with nReps set to 1 is executed once. Unless you set some parameter in that loop, it is essentially equivalent to an experiment run without the loop. So your loop observation does not seem to be essential to your experiment.
  2. The same seems to be true for the loops dots_obs_l and dots_obs_r which you initialise with 1 at the beginning of the experiment. If you do not change this value during the course of the experiment, you do not need the loops.
  3. If you change the value of dots_obs_l and dots_obs_r after initialising them, you must do so before their respective loops are executed.
  4. Also make sure that you use the same name for the loop and nReps, dots_obs_l and dots_obs_r. Avoid using the same name twice.
  5. only tick is trials in the loop definition if it really is a trial. So it is probably sufficient to tick this only for the innermost loop.

If trials between blocks differ only in the stimuli presented, their location aso., it is better to reuse a routine than to create an extra routine for each stimulus configuration.

Best wishes Jens

I have tried putting the code into the “before experiment” tab, but nothing seemed to change.
Here is the routines:

Thank you! I have modified these areas, hopefully this will make it run more smoothly.

Hello Claire


  1. you initialize dots_obs_l and dots_obs_r with 1 at the beginning of the experiment. Do you ever change the value of these variables?
  2. why do you use obs_random_r.stop() and obs_rand_l.stop()? You set the duration of the video in obs_random_r and obs_random_l, don’t you. Do you need these statements?

Best wishes Jens

Hi Jens,
No the dots_obs_l and dots_obs_r stay the same throughout the experiment. Do I need to set it to a different value?
I use the stop code so that the videos stop playing, to let the next videos play without overlap.


Hello Claire,

I do not know if you need to set dots_obs_r/l to a different value. You have to know. :wink: You define how often the loops dots_obs_rl/ are repeated. So if it is not necessary for your experiment that the loops are repeated and you never change the value of dots_obs_r/l from 1, you can simply delete the variables and the loops dots_obs_r/l.

Best wishes Jens

Thanks Jens!
I have changed it so that dots_obs_l/r run 3 times as I had planned. This seemed to get rid of the error and it runs for longer but then it stops again. Also, it gets rid of the randomisation of the loop (i.e. it just plays left three times and then right three times and then stops with the same error).

Hello Claire,

  1. I don’t know what your experiment will look like. So you need to give a detailed description, comparable to a method section.
    2: You write that you have fixed the bug, and then it stops with the same bug. Either the bug is gone or it is not.
  2. If you want three iterations of dots_obs_l and dots_obs_r, you should set it directly in nReps instead of using a constant.
  3. Create a basic toy version of your experiment (*.psyexp, Excel files, stimuli), focusing only on the part that supposedly causes the error, and post it here or make your project available on Pavlovia/gitlab.

Best wishes Jens