Error (NameError: name 'instructionsspecloopnreps' is not defined) that appears sometimes while the experiment is working

Dear all,

OS: Mac OS 10.15.7
PsychoPy version: v2021.2.3
Standard Standalone? yes
What are you trying to achieve?:
I am trying to build an experiment whereas the participants will receive instructions in different time points based on the subgroup that they belong to. More specifically, the subgroup A will receive general and specific instructions right after the “welcome message” and the subgroup B will receive general instructions after the “welcome message” and specific instructions after some time in “condition 1”.
What did you try to make it work?:

  1. I have added to the Info Dialog the variable “subgroup” and I add the letters A or B accordingly.

  2. This is my Builder with the Components related in red square:

  3. I have added a Code Component in the “general_instructions” Routine:

Including the following code in the “Begin Experiment”:

if expInfo['subgroup'] == "A" :
    instructionsspecloopnreps = 1
    instructionsspecloopnrepsb = 0
elif expInfo['subgroup'] == "B" :
    instructionsspecloopnreps = 0
    instructionsspecloopnrepsb = 1
  1. The content of the “instructions_spec_loop” is:
    loopType: random
    Is trials: unchecked
    nReps: instructionsspecloopnreps

  2. Regarding “condition1”, I have added the following code in a Code Component:

if money_1 == 'add50_euro1' :
    totalamount_con1 = 2250 + 50
    msgfeedb_con1 = "You earned 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(2300)
    totalAmount2.append(2300)
    if expInfo['subgroup'] == "A" :# This relates with my problem
     instructionsspecloopnrepsb = 0 # This relates with my problem
    elif expInfo['subgroup'] == "B" : # This relates with my problem
     instructionsspecloopnrepsb = 0 # This relates with my problem
elif money_1 == 'rem50_euro1' :
    totalamount_con1 = 2300 - 50
    msgfeedb_con1 = "You lost 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(- 50)
    totalAmount2.append(- 50)
elif money_1 == 'add50_euro2' :
    totalamount_con1 = 2250 + 50
    msgfeedb_con1 = "You earned 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(+ 50)
    totalAmount2.append(+ 50)
elif money_1 == 'rem50_euro2' :
    totalamount_con1 = 2300 - 50
    msgfeedb_con1 = "You lost 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(- 50)
    totalAmount2.append(- 50)
elif money_1 == 'rem50_euro3' :
    totalamount_con1 = 2250 - 50
    msgfeedb_con1 = "You lost 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(- 50)
    totalAmount2.append(- 50)
elif money_1 == 'add50_euro3' :
    totalamount_con1 = 2200 + 50
    msgfeedb_con1 = "You earned 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(+ 50)
    totalAmount2.append(+ 50)
elif money_1 == 'rem50_euro4' :
    totalamount_con1 = 2250 - 50
    msgfeedb_con1 = "You lost 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(- 50)
    totalAmount2.append(- 50)
    if expInfo['subgroup'] == "B" : # This relates with my problem because I want after 7 times in condition1 the participants in subgroup B (and only them) to be presented with the specific instructions
     instructionsspecloopnrepsb = 1 # This relates with my problem
elif money_1 == 'rem100_euro1' :
    totalamount_con1 = 2200 - 100
    msgfeedb_con1 = "You lost 100 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(- 100)
    totalAmount2.append(- 100)
    instructionsspecloopnrepsb = 0  # This relates with my problem
  1. The content of the “condition1_instructionsspec_loop” is (as seen in red square):
    loopType: random
    Is trials: unchecked
    nReps: instructionsspecloopnrepsb

What specifically went wrong when you tried that?:
The problem is that sometimes the experiment works as I want by presenting the instructions for subgroup A and subgroup B in correct order and other times, without any intervention by me, the experiment stops after the “general_instructions” Component and I receive this message:

Generating PsychoPy script…

##Running: /Users/pauline/Desktop/Academic/University Of Cyprus/5 Έτος/Εαρινό Εξάμηνο 2021-2022/Εργαστήριο Αναπτυξιακής Ψυχοπαθολογίας/Πτυχιακή Εργασία/Task in Computer/exp1_subgr1_fille/exp1_subgr1_lastrun.py ##
28872.1755 INFO Loaded monitor calibration from [‘2021_11_28 10:53’]
0.8941 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use [‘sounddevice’, ‘PTB’, ‘pyo’, ‘pygame’] (in that order).
2022-04-04 09:56:13.342 python[3320:4064364] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/fv/td94jv0d44jdnknw9qmk77_00000gn/T/org.opensciencetools.psychopy.savedState
Traceback (most recent call last):
File “/Users/pauline/Desktop/Academic/University Of Cyprus/5 \u0388\u03c4\u03bf\u03c2/\u0395\u03b1\u03c1\u03b9\u03bd\u03cc \u0395\u03be\u03ac\u03bc\u03b7\u03bd\u03bf 2021-2022/\u0395\u03c1\u03b3\u03b1\u03c3\u03c4\u03ae\u03c1\u03b9\u03bf \u0391\u03bd\u03b1\u03c0\u03c4\u03c5\u03be\u03b9\u03b1\u03ba\u03ae\u03c2 \u03a8\u03c5\u03c7\u03bf\u03c0\u03b1\u03b8\u03bf\u03bb\u03bf\u03b3\u03af\u03b1\u03c2/\u03a0\u03c4\u03c5\u03c7\u03b9\u03b1\u03ba\u03ae \u0395\u03c1\u03b3\u03b1\u03c3\u03af\u03b1/Task in Computer/exp1_subgr1_fille/exp1_subgr1_lastrun.py”, line 577, in
instructions_spec_loop = data.TrialHandler(nReps=instructionsspecloopnreps, method=‘random’,
NameError: name ‘instructionsspecloopnreps’ is not defined
#####Experiment ended. #####

Thank you very much for your attention and your time,
Pauline

Put instructionsspecloopnreps = 0 in a **Begin Experiment ** code tab

Hello Mr Morys-Carter,

I accidentally published my previous question without having explained my problem :slight_smile:. Unfortunately I have added “instructionsspecloopnreps = 0” in a " Begin Experiment" code tab, but the problem remains the same. Thank you very much for your response and you time.

Reattach your master spreadsheet and check it doesn’t have extra blank rows. I just solved a similar issue elsewhere due to this.

Dear Mr Morys-Carter,

First of all, thank you very much for your time and your response.
Secondly, I am a little bit confused of where I have to re-attach my master spreadsheet as I have not added any conditions file in my two loops created for achieving my goal. More specifically:

This my builder and the contents of my loop:

For a reminder:

I have added a Code Component in the “general_instructions” Routine including the following code in the “Begin Experiment”:

if expInfo['subgroup'] == "A" :
   instructionsspecloopnreps = 1
   instructionsspecloopnrepsb = 0
elif expInfo['subgroup'] == "B" :
   instructionsspecloopnreps = 0
   instructionsspecloopnrepsb = 1

and regarding “condition1”, I have added the following code in the “Begin Routine”:

if money_1 == 'add50_euro1' :
    totalamount_con1 = 2250 + 50
    msgfeedb_con1 = "You earned 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(2300)
    totalAmount2.append(2300)
    if expInfo['subgroup'] == "A" :# This relates with my problem
     instructionsspecloopnrepsb = 0 # This relates with my problem
    elif expInfo['subgroup'] == "B" : # This relates with my problem
     instructionsspecloopnrepsb = 0 # This relates with my problem
elif money_1 == 'rem50_euro1' :
    totalamount_con1 = 2300 - 50
    msgfeedb_con1 = "You lost 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(- 50)
    totalAmount2.append(- 50)
elif money_1 == 'add50_euro2' :
    totalamount_con1 = 2250 + 50
    msgfeedb_con1 = "You earned 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(+ 50)
    totalAmount2.append(+ 50)
elif money_1 == 'rem50_euro2' :
    totalamount_con1 = 2300 - 50
    msgfeedb_con1 = "You lost 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(- 50)
    totalAmount2.append(- 50)
elif money_1 == 'rem50_euro3' :
    totalamount_con1 = 2250 - 50
    msgfeedb_con1 = "You lost 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(- 50)
    totalAmount2.append(- 50)
elif money_1 == 'add50_euro3' :
    totalamount_con1 = 2200 + 50
    msgfeedb_con1 = "You earned 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(+ 50)
    totalAmount2.append(+ 50)
elif money_1 == 'rem50_euro4' :
    totalamount_con1 = 2250 - 50
    msgfeedb_con1 = "You lost 50 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(- 50)
    totalAmount2.append(- 50)
    if expInfo['subgroup'] == "B" : # This relates with my problem because I want after 7 times in condition1 the participants in subgroup B (and only them) to be presented with the specific instructions
     instructionsspecloopnrepsb = 1 # This relates with my problem
elif money_1 == 'rem100_euro1' :
    totalamount_con1 = 2200 - 100
    msgfeedb_con1 = "You lost 100 euro. The amount of money that you have now is {} euro.".format(totalamount_con1)
    totalAmount.append(- 100)
    totalAmount2.append(- 100)
    instructionsspecloopnrepsb = 0  # This relates with my problem

Thank you very much for your time,
Pauline