Crash in pilot mode

OS macOS Tahoe 26.61.
PsychoPy version 2026.1.3
Standard Standalone Installation? (y/n) y
Do you want it to also run online? (y/n) y
What are you trying to achieve?:

I use the following code to counterbalance groups in a research class experiment

index1 = []
index2 = []

if int(expInfo['participant']) % 2 == 0:
    index1 = list(range(5, 21)) 
    shuffle(index1)
    index2 = list(range(21, 37)) 
    shuffle(index2)
else:
    index1 = list(range(21, 37))
    shuffle(index1)
    index2 = list(range(5, 21))
    shuffle(index2)

index1.extend(index2)

Link to the most relevant existing thread you have found:

But this is rather old and I am not sure whether this still applies.

What specifically went wrong when you tried that?:
This code throws the following error in pilot-mode but not in run-mode

if int(expInfo['participant']) % 2 == 0:
ValueError: invalid literal for int() with base 10: 'pilot'

I am not sure whether it is related to running the experiment on a Mac.? It ran on a Win11-machine last semester without any problems.

Any hints?

Best wishes Jens

When you run an experiment in pilot mode the participant field is set to “pilot” instead of the given value (e.g. f"{randint(0, 999999):06.0f}"). You can suppress this behaviour via Preferences / Pilot mode / replaceParticipantID or deal with the pilot value explicitly in your code.

Hello

I found my mistake. PsychoPy sets the participant number to “Pilot” when piloting. This cause the code to fail.

The following code circumvents this problem.

consent = 0
index1 = []
index2 = []

if expInfo['participant'] == 'pilot':
    participant_num = 0 
else:
    participant_num = int(expInfo['participant'])

if participant_num % 2 == 0:
    index1 = list(range(5, 21))
    shuffle(index1)
    index2 = list(range(21, 37))
    shuffle(index2)
else:
    index1 = list(range(21, 37))
    shuffle(index1)
    index2 = list(range(5, 21))
    shuffle(index2)
    
index1.extend(index2)

Best wishes Jens