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)

Hello @TParsons, I ended up downloading the newest version and still have problems running it. I had a research assistant try to open it as well and for her it didn’t even open the instructions whereas for me it crashed before the first trial. Do you have any ideas why this may be happening?

From the looks of things, you have these variables defined in the JS tab of the Code component, but not Python. So these will only be defined when running online, for them to also exist when running locally you need to also define them in Python too

1 Like

Oh I can’t believe I didn’t notice that!!! Thank you so much!!!