Experiment repeating too many times (Psychopy beginner using Builder)

OS Win10
PsychoPy version V2023.2.3
What are you trying to achieve?: I need to limit the number of repetitions

What did you try to make it work?: Reducing the number of conditions in the spreadsheet

What specifically went wrong when you tried that?:
Include pasted full error message if possible:
line 183, in setSound
raise ValueError(msg + value)
ValueError: setSound: could not find a sound file named snd1
################# Experiment ended with exit code 1

Hi Folks, I’m very much a beginner with Psychopy. While I have experience coding in other languages, I’m trying to use the Builder to produce a task that simply plays a randomly selected sound from one set (1sec,wav and so on in the conditions file), then plays a further random selection from a different set of 5 sounds (1secnoise.wav etc.), then a another random sound from the first set, continuing to alternate between the two sets until 40 sounds in total have been played.

I produced a conditions file with a total of a hundred conditions, as follows:

gap stim
snd1 1sec.wav snd2 1secnoise.wav
snd1 2sec.wav snd2 1secnoise.wav
snd1 3sec.wav snd2 1secnoise.wav
snd1 4sec.wav snd2 1secnoise.wav
snd1 5sec.wav snd2 1secnoise.wav
snd1 6sec.wav snd2 1secnoise.wav
snd1 7sec.wav snd2 1secnoise.wav
snd1 8sec.wav snd2 1secnoise.wav
snd1 9sec.wav snd2 1secnoise.wav
snd1 10sec.wav snd2 1secnoise.wav
snd1 11sec.wav snd2 1secnoise.wav
snd1 12sec.wav snd2 1secnoise.wav
snd1 13sec.wav snd2 1secnoise.wav
snd1 14sec.wav snd2 1secnoise.wav
snd1 15sec.wav snd2 1secnoise.wav
snd1 16sec.wav snd2 1secnoise.wav
snd1 17sec.wav snd2 1secnoise.wav
snd1 18sec.wav snd2 1secnoise.wav
snd1 19sec.wav snd2 1secnoise.wav
snd1 20sec.wav snd2 1secnoise.wav
snd1 1sec.wav snd2 2secnoise.wav
snd1 2sec.wav snd2 2secnoise.wav
snd1 3sec.wav snd2 2secnoise.wav
snd1 4sec.wav snd2 2secnoise.wav
snd1 5sec.wav snd2 2secnoise.wav
snd1 6sec.wav snd2 2secnoise.wav
snd1 7sec.wav snd2 2secnoise.wav
snd1 8sec.wav snd2 2secnoise.wav

etc., etc., etc… which has produced an experiment that works, although it’s running through far too many repetitions. I had though that setting the “nReps” to 20 in the loop’s menu would result in a task that just looped twenty times, however, after researching nReps here I’ve realised that it’s going to present all of the stimuli 20 times, which is far too long. Can anyone advise me on a way to limit this experiment so that it just loops 20 times? I have tried reducing the conditions file but that resulted in the error copied into the template above.

Any advice or help is appreciated.


you could use the Selected row parameter of the loop. It enables to select a subset of your stimuli.

Best wishes Jens

1 Like

If you want to break out of a loop called trials after 40 trials (randomly selected from a larger number in a spreadsheet) add the following code in a component within the loop. End Routine might make most logical sense but Begin Routine also works.

if trials.thisN == 39:
     trials.finished = True

Thanks Jens, but I need the task to be able to select any twenty of the hundred conditions. Just selecting particular rows would limit the available selections, I think? I’m wondering if some sort of coded counter that will increment and end the loop after twenty iterations is the way to go? I don’t have any experience of Python but am looking for solutions.

Thanks Wakefield, I think that’s what I need. I’ll try and implement that shortly. Much appreciated! :slight_smile:


@wakecarter’s solution is an elegant approach.

My approach needs more code :wink:

In Begin Experiment

rows = list(range(0,20))

rowsSelect = str(rows[0:5])


The example randomly selects 5 rows out of 20 rows.

Best wishes Jens

Thanks Jens, that’s also much appreciated. :slight_smile:

Hi again Wakefield, your code works and the experiment is now running as needed. I know it may have seemed like something really simple to you but I am a real beginner with this, I got given the task of using Psychopy to produce this task even though I am a genuine beginner. I really do appreciate your help. Thanks again. :smile:

I’ll file this away for future reference Jens, thanks again. :smiley: