NameError: name ___ is not defined

There are three common causes for NameError: name xxxxx is not defined:

  • Not having selected the Set every repeat option for a variable parameter to your Component (but in the particular case above that isn’t relevant because the error is coming up in a Code Component)
  • a typo in the name. Check very carefully that your capitals match those in your conditions file
  • an ordering problem (the variable being used before it has been defined).
    • If the variable is in a conditions file then it won’t be created until the relevant loop begins.
    • If your Code Component is used in multiple places, or if it has code in the Begin Experiment box then this might be executed before the variable has been created. You could add something to initialize your variable with some default value in the Begin Experiment box to be sure
3 Likes