TypeError: Cannot read properties of undefined (reading '0') in Random Dot Motion task on Pavlovia

Hi,
I have created a random dot motion experiment in Psychopy, to be used in an online study.
It runs in-app on Psychopy and is synced with my Pavlovia account. The URL for the experiment is given below.

URL of experiment:
https://run.pavlovia.org/claireflynn/randomdotmotion

Description of the problem: The experiment runs and shows the instruction pages but an error message pops up on the screen when the dot stimuli are supposed to appear. The message reads “TypeError: Cannot read properties of undefined (reading ‘0’)”. When I look into the task code the following errors are shown:

PsychoJS.js:730 TypeError: Cannot read properties of undefined (reading ‘0’)
at Object.next (TrialHandler.js:158:47)
at Scheduler._currentTask (final_rdm.js:1290:16)
at Scheduler._runNextTasks (Scheduler.js:215:24)
at async Scheduler._runNextTasks (Scheduler.js:222:13)
at async Scheduler._runNextTasks (Scheduler.js:222:13)
at async Scheduler._runNextTasks (Scheduler.js:222:13)
at async update (Scheduler.js:136:18)
window.onunhandledrejection @ PsychoJS.js:730
log4javascript.js:148 FATAL 16:27:45.634 _GUI.dialog psychojs-2022.2.4.js:1257 | {}
BrowserConsoleAppender.append @ log4javascript.js:148
TrialHandler.js:158 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘0’)
at Object.next (TrialHandler.js:158:47)
at Scheduler._currentTask (final_rdm.js:1290:16)
at Scheduler._runNextTasks (Scheduler.js:215:24)
at async Scheduler._runNextTasks (Scheduler.js:222:13)
at async Scheduler._runNextTasks (Scheduler.js:222:13)
at async Scheduler._runNextTasks (Scheduler.js:222:13)
at async update (Scheduler.js:136:18)

I am not sure where to start with debugging the code in order for the task to run online.

Any help would be greatly appreciated.

Thank you.

Hello,
Can you please share your code? Show us the part of your code that raises the error (it’s somewhere after the instructions).
Your experiment is private:

Hi, I have changed the settings to public so you should be able to see the code now.

The problem is with the nRep in your loops:
image

The variable dots_obs_l/dots_obs_r is not read or declared correctly in the JS code.
Not sure what the solution is, but it might bring us someone who faced this problem.

Hello,

The variable dots_obs_l is also not declared correctly. So you could add a JavaScript-only code component and declare dots_obs_l and dots_obs_r in a Begin experiment tab.

dots_obs_r = someValueYouPick;
dots_obs_l = someValueYouPick;

By the way, your experiment is too complex and doesn’t make use to PsychoPy’s ability to reuse routine. Take for example instruction1 to instruction3. Instead of creating four routines, you could just use one routine and use a loop to change the instruction texts. The same goes for obs_l and obs_r, trial_1_coh, trial_2_coh. Just reuse the routine and make the things that are different between trial_1_coh and trial_2_coh variables that you set or read in via an Excel-sheet. This would make maintenance a lot easier.

Best wishes Jens

1 Like

Hi,
I tried to add in a code component declaring these two loops, the experiment is running for longer but only shows the text component ‘TARGET’ twice and no dots, and then crashes again with the same error.

Thanks,
Claire

Hello Claire

I do not have access to your project and you don’t show any relevant code here such as how and where do you declare the variables dots_obs_r, how do you set the dots, where do you set the text component target aso.

Best wishes Jens

Hi Jens,
I declared the dots_obs_r in a new code component as shown by the code below:

// Initialize components for Routine “obs_setup”
obs_setupClock = new util.Clock();
dots_obs_l = 1
dots_obs_r = 1
// Initialize components for Routine “obs_ran”
obs_ranClock = new util.Clock();
obs_ran_fix_cross = new visual.ShapeStim ({
win: psychoJS.window, name: ‘obs_ran_fix_cross’,
vertices: ‘cross’, size:[0.05, 0.05],
ori: 0.0, pos: [0, 0],
lineWidth: 1.0,
colorSpace: ‘rgb’,
lineColor: new util.Color(‘white’),
fillColor: new util.Color(‘white’),
opacity: undefined, depth: 0, interpolate: true,
});

// Initialize components for Routine “obs_l”
obs_lClock = new util.Clock();
obs_l_text = new visual.TextStim({
win: psychoJS.window,
name: ‘obs_l_text’,
text: ‘TARGET\n’,
font: ‘Open Sans’,
units: ‘height’,
pos: [0.0, 0.2], height: 0.05, wrapWidth: undefined, ori: 0.0,
languageStyle: ‘LTR’,
color: new util.Color((1.0000, -0.5137, -0.5137)), opacity: undefined,
depth: 0.0
});

obs_l_fix_cross = new visual.ShapeStim ({
win: psychoJS.window, name: ‘obs_l_fix_cross’,
vertices: ‘cross’, size:[0.05, 0.05],
ori: 0.0, pos: [0, 0],
lineWidth: 1.0,
colorSpace: ‘rgb’,
lineColor: new util.Color(‘white’),
fillColor: new util.Color(‘white’),
opacity: undefined, depth: -1, interpolate: true,
});

// Initialize components for Routine “obs_r”
obs_rClock = new util.Clock();
obs_r_text = new visual.TextStim({
win: psychoJS.window,
name: ‘obs_r_text’,
text: ‘TARGET\n\n\n’,
font: ‘Open Sans’,
units: ‘height’,
pos: [0.0, 0.2], height: 0.05, wrapWidth: undefined, ori: 0.0,
languageStyle: ‘LTR’,
color: new util.Color((1.0000, -0.5137, -0.5137)), opacity: undefined,
depth: 0.0
});

obs_r_fix_cross = new visual.ShapeStim ({
win: psychoJS.window, name: ‘obs_r_fix_cross’,
vertices: ‘cross’, size:[0.05, 0.05],
ori: 0.0, pos: [0, 0],
lineWidth: 1.0,
colorSpace: ‘rgb’,
lineColor: new util.Color(‘white’),
fillColor: new util.Color(‘white’),
opacity: undefined, depth: -1, interpolate: true,
});

Hello Claire

I do not “speak” JavaScript. I rely most of the time on the auto-translation feature of PsychoPy to PsychoJS and correct the errors that the auto-translation has not translated correctly. But I see that you forgot to add a semicolon at the end of the line dots_obs_l and at the end of the line dots_obs_r.

It is good practice to show the flow and the relevant parts of the experiment. Also, enclosing your code in triple ` will format it properly and make it easier to read.

Best wishes Jens

Hi Claire,
The rest of your program appears to be working, but I think it’s the DOTS that’s the issue on pavlovia. I believe there is an issue as they didn’t translate over and that’s why they’re not visible. If you look at the javascript, none of the variables for the dots are in the code. I think there is a prototype that I found from a previous message on here, but it appears that the dots is a prototype and does not work on pavlovia…

https://www.psychopy.org/online/status.html

but if anyone can give us an update that would be great.

thanks,

Colin

1 Like

Hi,

I have modified the experiment to use video stimuli instead of the dots, to avoid the problem with the dot stimuli online. But I am still facing some issues.
The video stimuli work within the experiment for the most part but at the end of the loops (dots_obs_l, dots_obs_r), one of the videos stops playing. I have included a recording of this below. This happens in the practice round and testing blocks as well. In addition, the experiment includes 3 blocks of testing trials, and on the second and third trial, none of the target videos appear on the screen. I’m not sure how to fix this because the videos are running in general, so it must not be the code for the stimuli themselves.

Also, when running the experiment online using Pavlovia, the videos run for a few seconds and then I am facing the same error as before. I have tried adding in the code component defining the loops (with the semicolons) but there seems to be another issue.

Any help would be much appreciated.
Thank you,
Claire

1 Like