Create one psyexp file that will assign participants randomly to one of four conditions?

I am teaching participants one of two made-up languages (A or B), with either one or two rounds of training before a short test, for a total of four experimental conditions (A1, B1, A2, B2). I’d really like to do this in builder as much as possible and then finally run it on Pavlovia (but recruiting through SONA, so not sure if @wakecarter’s sequential participant ID application ( will work?). The sub-tasks of the experiment occur in the same order for each participant.

I’m a bit confused by the other answers I’ve seen to similar questions as well as the Blocks of Trials & Counterbalancing (Blocks of trials and counterbalancing — PsychoPy v2021.2.4) / Counterbalancing Online (Counterbalancing online — PsychoPy v2021.2.4) instructions. If I’m understanding right, I would need a code component assigning participants to one of the four conditions (ideally doing something like routing through the sequential participant ID app to use something like a participant_ID%4) an outer loop with a condition file pointing to A1, A2, B1, and B2, and then the rest of the experiment can go on as usual. Is it possible to then have separate “instructions” for the loops in the {A, B}2 conditions to have two repetitions of the training loop? Or would I have to use a separate psyexp file for them?


wakecarter’s sequential participant id will work. When recruiting using SONA you could use a code generated on SONA to assign participants to different groups. And yes you need some code to determine the group assignment on the basis of the participant id. Notice that these approaches do not take into account that participants might not finish the experiment. Therefore the participant count per group might be off. If you want an even distribution you might want to take a look at the vespr-tool

It is possible to have different instructions based on the group assignment.

All can be done in one experiment aka psyexp-file.

Best wishes Jens


Now my question is the best way of associating the four conditions with their instructions, training stimuli, and test stimuli. My first thought is, since the flow will be the same for each condition, I can have something like 'instructions/training/test' + expInfo['group'] + '.xlsx' in the loop for each component (so instructions1,2,3,4; training1,2,3,4; test1,2,3,4) to select the relevant excel file for the loops.

I think that’s the most parsimonious (and easiest for me to troubleshoot if something goes wrong), but I’m open to other options.

The second part to this question is that I have a very similar version of this experiment, 4 conditions, same setup, except the number of times the training is repeated is different in two conditions: in condition 1 and 2, the training is repeated twice; in condition 3 and 4, the training is repeated once. In the repeat-twice conditions, I want to make sure that participants complete one repetition before starting on the next repetition, and I’d also like to have each repetition randomized (if they have stimuli ABCD, I would like them to see something like BACD - ACDB before they move onto the test). Is there a way to do THIS in one .psyexp file?

Your suggestion should work, but the most parsimonious is to have one spreadsheet (i.e. one instructions, one training, one test) and then use a variable, say useRows, to select which rows are read.

For example, if there are 10 rows for each group and you are using group from the VESPR Study Portal, you could have:

useRows = str(int(expInfo['group']*10-10)+':'+str(int(expInfo['group']*10)

useRows would then be 0:10, 10:20, or 20:30

For your second point, I think you want nReps to be a variable set to 2 or 3. Random will select the rows at random and then start again, as opposed to Full Random, which will shuffle across all the repeats.

That makes sense for the first point, thanks!

For the second point, can I set the nReps to only apply to two conditions out of four? I don’t immediately see a way to do this, but maybe with some kind of if/else where condition{1,2} get nReps=2 and otherwise they get nReps=1?

You need to set nReps to a variable and then assign 1 or 2 to that variable.