Jdigg
January 11, 2022, 1:21pm
1
URL of experiment: FYP [PsychoPy]
Description of the problem:
When running the experiment on Pavlovia, before the block I get the error:
TypeError: Cannot read properties of undefined (reading ‘0’)
Using the console it shows:
The error is on the first line of this:
this.thisIndex = this._trialSequence[this.thisRepN][this.thisTrialN];
this.thisTrial = this.trialList[this.thisIndex];
this.ran = 1;
this.order = this.thisN;
I do use code to specify the number of reps in the final block using $choiceBlockReps , which is defined earlier in the experiment, is this likely to be where the issue is?
Thank you
Jake
Try removing the $ from choiceBlockReps
@elizabeth_sokolenko , you need to remove the $ from your nReps field in the loop, as the $ sign is being written to the JS and causing the Reference Error. As the nReps field already uses a dollar sign by default, you do not need to use one as well, but I have raised an issue to get this fixed in cases where users do enter a $:
Jdigg
January 12, 2022, 9:50am
3
The $ is hard coded into the nReps bit, not part of the separate code. Thought we’d got it then!
The code for my reps is
choiceBlockReps = len(imgL)
Could that be causing the issue? Though it follows what was recommended to me by Becca and her Pavlovia upload runs fine using len(list) as the value for reps.
Is your loop pointing at a spreadsheet? Please could you show a screenshot of its definition?
Try print('choiceBlockReps',choiceBlockReps)
just after the above line of code to check it is being set correctly in the console.
Jdigg
January 12, 2022, 10:38am
5
The loop does not have a spreadsheet, the images are chosen from earlier code.
Adding the print code gave me:
choiceBlockReps 59
which is accurate for the choices I made during that run.
That all looks fine. Are you using trialsChoice for anything else?
Jdigg
January 12, 2022, 11:21am
7
It’s used in the image call up:
It’s also referenced in the code to save the extra data
thisExp.addData('Image Left', imgL[trialsChoice.thisN])
thisExp.addData('Image Right', imgR[trialsChoice.thisN])
I have now also made the git repo public Jake Diggins / IM_FYP2122 · GitLab
Jdigg
January 13, 2022, 8:48am
8
I have managed to finally fix this issue.
I had to move the choiceBlockReps code from “begin routine” to “end routine” and it works perfectly.
Is this a quirk of JS? As it was able to accept the variable fine from where it was in Python.
I tend to have most of my code in Begin Routine.
It is also good practice to move the code component to the top of the routine, so that Begin Routine is processed before any Each Repeat components.
One quirk of JS is that the first time a variable is assigned, it needs to be outside any brackets.
For example:
if random() > .5:
condition = 1
else:
condition = 2
will fail with a condition not defined error but
condition = 2
if random() > .5:
condition = 1
is fine.