| Reference | Downloads | Github

Online experiment - TypeError: Cannot read property '0' of undefined

URL of experiment: Language, Cognition and Development Lab / Triplet Game · GitLab

Description of the problem:
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 I’m telling it to run 25 trials for both blocks, however, when I’m piloting the study and get to the second block, I get this error.

For piloting purposes, if I set numEncoding = 2 and numRetrieval = 4 in the first block, and do the same for the second block, I can run the whole task. However, when I set numEncoding = 25 and numRetrieval = 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

Are you using .thisN anywhere?

You should look at the console to identify which line is giving the error.

Hi @wakecarter, I don’t think I am using .thisN anywhere. It works if I only do a few trials, not sure why these numbers are giving me the error. I inspected the page source and saw this:

“core-2021.1.4.js:1923 TypeError: Cannot read property ‘0’ of undefined
at Scheduler._currentTask (TripletsGame.js:2723)
at Scheduler._runNextTasks (util-2021.1.4.js:1560)
at Scheduler._runNextTasks (util-2021.1.4.js:1564)
at Scheduler._runNextTasks (util-2021.1.4.js:1564)
at update (util-2021.1.4.js:1514)
window.onerror @ core-2021.1.4.js:1923
log4javascript.min.js:1 FATAL unknown | {}”

Am I looking at the correct spot? Should I be doing anything else?
Thank you,

What’s that line of your JS file?

Hi @wakecarter ,

The line 2723 is like this:

For the 1560 and 1564:

How is t1 defined?

I haven’t defined t1 anywhere in the code, it’s just the name of the image component, which I assign ‘triplet 1’ to. So that should be the first image of the triplet! Was I supposed to define the image components in the code_JS part?

No – but there may be a problem with one of the parameters. What do they look like?

You could try console.log('triplet1',triplet1) to check that the image has been assigned correctly.

@wakecarter thank you! I am trying that however it seems that it doesn’t even get as far to assign something to triplet1 for block 2, I just get the error. Do you have suggestions on what I can use to test js code locally? I downloaded node.js but can’t seem to run this experiment locally.

1 Like