Experiment won't work when calling a defined list variable in 'Selected rows' of loop

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2020.2.1
Standard Standalone? (y/n) : Yes

What are you trying to achieve?:

I have an experiment which has counterbalanced two conditions according to participant group (specified as Group A or B in the Experiment Info). My loop selects the appropriate conditions spreadsheet based on the participant group.

I need my variable (a list of 90 words) to be randomised across all three conditions (30 words in each condition) - 1 condition is always presented first, and the other two are counterbalanced. The way I have done this is to add some code into a code component which makes some list variables of random numbers, which I can then call in the ‘Selected rows’ section of the loop.

Though my code seems to do what it’s supposed to when debugged in Visual Studio Code, the experiment isn’t working properly, and I can’t figure out why.

What did you try to make it work?:

Here is my flow. You can see the first condition only has one loop (trials) as there is no counterbalancing, and the second part is nested in the outer loop called ‘counterbalance’, which is where the next two conditions are counterbalanced:

My code component in the routine named ‘task2’ is called ‘code2’ and contains the following relevant to what I am trying to do:

Before experiment
import random

Begin experiment

controlStims = random.sample(range(1, 90), 30) 
#make list for control condition

AOMIstims = [] #make list for AOMI conditions
while len(AOMIstims) < 60: #60 numbers
            r = random.randint(1,90) #ranged 1-90
            if r not in AOMIstims: 
                  if r not in controlStims:
                        AOMIstims.append(r) #only add to list if not already there, and not in controlStims
            if r in AOMIstims:
                continue
                AOMIstims += [r] 

half = len(AOMIstims)/2
list1 = AOMIstims[:int(half)]
list2 = AOMIstims[int(half):] 
#cut the AOMIstims list in half so we have two lists of 30 numbers

Then in my routine, ‘instructions_AOMI’ before the ‘trials_2’ loop begins, I have another code component called, ‘code_AOMIrows’, which looks like this:

End routine

def AOMIrowSelector(list1, list2):
      if condsFile == "AOMIspec_trials.xlsx":
            return list1
      else:
            return list2 
#function so that different lists are selected
            #for different AOMI conditions

listSelect = AOMIrowSelector(list1, list2)

Please note that the variable ‘condsFile’ is specified in the spreadsheets 'OrderA.xlsx. and ‘OrderB.xlsx’ and refers to the conditions spreadsheets (e.g., ‘AOMIgen_trials.xlsx’ or ‘AOMIspec_trials.xlsx’ - see below for links).

Here are my loops. This is the loop for the first condition called ‘trials’, which seems to work fine:
image

Here is the counterbalancing loop:
image

And here is the loop called ‘trials_2’:
image

So, you can see in ‘Selected rows’ I am calling the variable I created in my code called ‘listSelect’.

I have attached my experiment file and my conditions spreadsheets below in case a closer look is needed. I couldn’t attach my media for some reason, so if you need to simulate my experiment hopefully you will be able to do so by turning off the audio and movie components.

OrderA.xlsx (8.6 KB)
OrderB.xlsx (8.6 KB)
AOMIgen_trials.xlsx (11.2 KB)
AOMIspec_trials.xlsx (11.3 KB)
control_trials.xlsx (12.1 KB)
StudentExperiment_shortVideos2_newCode.psyexp (58.7 KB)

What specifically went wrong when you tried that?:

The control condition works completely fine. It’s when the counterbalanced conditions start that things fail. Weirdly enough, SOMETIMES, the condition runs perfectly, and other times it doesn’t, and I have no idea why it only works some of the time. When it fails, the instructions screen (‘instructions_AOMI’) is displayed correctly, but once a button is clicked to begin the routine, ‘AOMI’, the experiment window closes and my cursor turns into an indefinite loading wheel.

After some time, eventually this error message appears in the Experiment Runner:

Traceback (most recent call last):
  File "C:\Users\g34890cw\Documents\PsychoPy\StudentCompExp\StudentExperiment_shortVideos2_newCode_lastrun.py", line 787, in <module>
    trialList=data.importConditions(condsFile, selection=listSelect),
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\data\utils.py", line 444, in importConditions
    trialList.append(allConds[int(ii)])
IndexError: list index out of range
Exception ignored in: <bound method TextStim.__del__ of <psychopy.visual.text.TextStim object at 0x0000017D78847FD0>>
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 240, in __del__
  File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\gl\lib.py", line 97, in errcheck
ImportError: sys.meta_path is None, Python is likely shutting down
Exception ignored in: <bound method TextStim.__del__ of <psychopy.visual.text.TextStim object at 0x0000017D7999DEB8>>
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 240, in __del__
  File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\gl\lib.py", line 97, in errcheck
ImportError: sys.meta_path is None, Python is likely shutting down
Exception ignored in: <bound method TextStim.__del__ of <psychopy.visual.text.TextStim object at 0x0000017D79985C50>>
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 240, in __del__
  File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\gl\lib.py", line 97, in errcheck
ImportError: sys.meta_path is None, Python is likely shutting down
Exception ignored in: <bound method TextStim.__del__ of <psychopy.visual.text.TextStim object at 0x0000017D7A2C8358>>
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 240, in __del__
  File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\gl\lib.py", line 97, in errcheck
ImportError: sys.meta_path is None, Python is likely shutting down
Exception ignored in: <bound method TextStim.__del__ of <psychopy.visual.text.TextStim object at 0x0000017D7A2C8400>>
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 240, in __del__
  File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\gl\lib.py", line 97, in errcheck
ImportError: sys.meta_path is None, Python is likely shutting down
Exception ignored in: <bound method TextStim.__del__ of <psychopy.visual.text.TextStim object at 0x0000017D7A2D0DA0>>
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 240, in __del__
  File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\gl\lib.py", line 97, in errcheck
ImportError: sys.meta_path is None, Python is likely shutting down
Exception ignored in: <bound method TextStim.__del__ of <psychopy.visual.text.TextStim object at 0x0000017D7A2D8278>>
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 240, in __del__
  File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\gl\lib.py", line 97, in errcheck
ImportError: sys.meta_path is None, Python is likely shutting down
Exception ignored in: <bound method TextStim.__del__ of <psychopy.visual.text.TextStim object at 0x0000017D7A2D8B70>>
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 240, in __del__
  File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\gl\lib.py", line 97, in errcheck
ImportError: sys.meta_path is None, Python is likely shutting down
Exception ignored in: <bound method TextStim.__del__ of <psychopy.visual.text.TextStim object at 0x0000017D7A2E0A58>>
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 240, in __del__
##### Experiment ended. #####

I really hope this is clear and makes sense. If anything is confusing, I am happy to clarify.

Any help with understanding why this sometimes does not work, and where the error may be in my code would be INCREDIBLY helpful.