| Reference | Downloads | Github

NameError: name 'numEncoding' is not defined

If this template helps then use it. If not then just delete and start from scratch.
PsychoPy version (e.g. 1.84.x): 3.2.3
What are you trying to achieve?: Defining number of encoding trials

**What did you try to make it work?:
This code used to work, however now I get the following error. I define ‘numEncoding = 25;’ in “begin routine” and I use “numEncoding” as number of repetitions in a loop. I still get this error when I move it to “begin experiment”. I’m working on this as I am modifying an experiment I got to run online before. I’m really not sure what the problem is since I did use this code before and it worked.

Here is the error:
“EncodingTrials = data.TrialHandler(nReps=numEncoding, method=‘random’,
NameError: name ‘numEncoding’ is not defined”.

Could you share the full .psyexp file? If you’re defining a variable in Before Experiment then it certainly should exist later - unless there’s a typo somewhere, or you clear your variables? I also notice you’re using an older version of PsychoPy so it might be worth upgrading to 2020.2.4 and seeing if the problem persists - it may well be a known bug which has been fixed since then.

1 Like

Hello @TParsons!! Thank you so much! Here is the psyexp file!

SpatialMem101220.psyexp (94.2 KB)