Experiment going unresponsive at this code

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win11
PsychoPy version (e.g. 1.84.x): 2023.2.1
Standard Standalone? (y/n) Y

I have built most of my experiment; the last thing I need to do is write a code so that based on participant number, every other cycle the participant either restudies the images or takes a practice test. I have a loop around my restudy routine, trials_4, and two practice test routines, which are surrounded by loop trials_5 (with an inner loop around one of these routines called trials_6). I have tried placing the following code in a routine right before these three routines, but as soon as the experiment gets to this routine it is becoming unresponsive and I have to end task. Is there anything obviously wrong with this code that would be causing this? It may be a terrible attempt at what I am trying to accomplish (I am very new to this)–this was a first try; I have not even yet been able to try to debug the code as I am not getting an error code…:

# Get participant number from user input or other method
participant_number = int(input("Enter participant number: "))

# Determine whether to start with restudy or practice test based on participant number
start_with_restudy = participant_number % 2 == 0
start_with_retrieval = participant_number % 2 == 1
current_cycle_indexP = int(trials_3.thisN)

# Begin Routine
if start_with_restudy:
    if current_cycle_indexP % 2 == 0:
        trials_5.setAutoDraw(False)
        trials_6.setAutoDraw(False)
        trials_4.setAutoDraw(True)
    else:
        trials_4.setAutoDraw(False)
        trials_5.setAutoDraw(True)
        trials_6.setAutoDraw(True)
if start_with_retrieval:
    if current_cycle_indexP % 2 == 0:
        trials_4.setAutoDraw(False)
        trials_5.setAutoDraw(True)
        trials_6.setAutoDraw(True)
    else:
        trials_5.setAutoDraw(False)
        trials_6.setAutoDraw(False)
        trials_4.setAutoDraw(True)

The begin routine code is indented–it just didn’t copy over that way

I’ve edited it for you (preformatted text)

My first thought is that you can’t (as far as I know) control a loop with setAutoDraw. Change the nReps to 0 to skip.

Thank you! I did try that, but it is still going unresponsive. If I disable the code routine the experiment runs fine, so I am sure it is this routine that is the problem. If it helps at all, I have a routine right before it that just displays the words “practice phase:” for 1 second, and it is freezing on that screen unless I disable the routine with the code. Additionally, in case the routine itself had a bug, I tried disabling that routine and adding a new one after it with the same code, and it is behaving the same way.

Could it be something with the line attempting to get the participant number?

I don’t recognise this code. Personally I would use participant_number = int(expInfo['participant'])

Thank you! I got it working by using this code inside the loop I was targetting:

Check if it’s a cycle to be skipped

if participant_number % 2 == 0 and current_cycle_indexP % 2 == 1:
continue # Skip the rest of the loop for this cycle

if participant_number % 2 == 1 and current_cycle_indexP % 2 == 0:
continue # Skip the rest of the loop for this cycle