Between-subject counterbalancing via pavlovia

URL of experiment:

Description of the problem:
Hi all,

I am wondering if we can set up between-subject counterbalancing when we recruit participants through online platforms (e.g. MTurk). For example, I want to have the conditions 1, 2, 3 and 4 running sequentially for the participants (Parti 1 = Cond 1; Parti 2 = Cond 2; …; Parti 5 = Cond 1;…)

So obviously we can input the condition number for the participants if they are in the lab, but is there a way for us to generate such sequential numbers according to where the participant is in the “line”?

Thanks a lot,

Hi Joyce,

half a year later, I am wondering the same thing. Did you find any way of implementing this method?


Hi Adrian,

No - we just ended up putting up multiple batches on MTurk, each with a specific URL for each condition we had.

However I believe a true counterbalancing is possible, as long as you can call the “number of workers completed the task” variable (I can’t recall the exact name) with the MTurk script, and then you can assign the condition number according to that variable in the JS code. Just that for the life of me I couldn’t figure out how to do that.

Good luck!

1 Like

Hi @Joyce_Tam -

Thank you for sharing your experience! I’m going to create three separate versions of my experiment to put up as separate batches on MTurk to achieve between-subject counterbalancing, too.

I’m wondering - when creating new Pavlovia experiments for each condition, how did you structure your local folder / file organization? Did you recreate the entire folder structure (with new copies of whatever stims/ resources your experiment needs) with a separate .psyexp file for each condition? Or were you able to create multiple .psyexp files within a single folder?

Thanks in advance -

From what I’ve learned, I don’t think sequential ordering is possible with conditions. Your best option would be to create two separate .psyexp experiments and share the link sequentially for each signup.

If, however, you are able to use the same experiment and simply change the .xlsx file, you can write a piece of code that will randomize which file (condition) is chosen. Then you can just keep a tally on each condition until a certain quota is reached, and continue experiments using the other file.

I’ve created four excel files called OrderA.xlsx, OrderB.xlsx, OrderC.xlsx, OrderD.xlsx. When specifying the condition in the trial loop, write: $'Order' + condition + '.xlsx'. The “OK” button might grey out but if you keep trying, it’ll become available.

Then create a code component in the same routine, and under the Begin Experiment tab, write:


import random
condition = random.choice(('A','B','C','D'))


function random_character() {
    var chars = "ABCD";
    return chars.substr( Math.floor(Math.random() * 4), 1);

condition = random_character(); 

If you only have two conditions, arrange accordingly, but in the Javascript code, make sure that (Math.random()) takes “2” instead of 4.

Hope this helps.

Yes, my method was similar to what Nicholas proposed, except I defined condition in expInfo, as I was able to change the tail of the URL to feed different values of objects in expInfo:

let expInfo = {'Participant': '','Condition':''};

then something like

if (expInfo['Condition']=='2'){

and of course BlockList was defined and List2 is a list with the desired block sequence.

I wrote some code to do this in PsychoPy but it won’t work online so my plan is to present the participant information sheet, assign a participant number ask for demographics and allocate to conditions via Qualtrics.

Best wishes,


1 Like

Assign Consecutive Participant IDs

I have written a web app. which can be used for Pavlovia experiments:

The page takes four parameters: folder, experiment, id and researcher.

folder (required) is your Pavlovia username

experiment (required) is your experiment name as formatted for the study link

id (optional) is a unique code which you could assign, for example as a random number in Qualtrics, so you can link your PsychoPy data back. It is passed to Pavlovia unchanged

researcher (optional) is also passed to Pavlovia unchanged. I am using it to ensure that participants start in Qualtrics where they can view the participant information sheet, not Pavlovia.

participant is assigned by my app. as a consecutive number. You could use a modulus of participant in order to assign participants to conditions. The number increments whether or not the participant finishes. It would be considerably more complicated to re-assign aborted participant numbers.

Example URL:


Thanks for making and sharing this application you made! It would be very helpful.

When I click on the link,, I just see this:

This webpage assigns consecutive participant numbers to experiments on Pavlovia. Please visit PsychoPy Python to Javascript crib sheet for more details.

Do you have any advice on how to use it?

My Pavlovia url is

This is what my URL to assign a participant number might look like.

Put your folder name where I have “Wake”
Put your experiment folder name where I have “prospective-memory-ldt”
The other two parameters are optional, and will be passed to Pavlovia.

In PsychoPy if you have condition = int([expInfo’participant’])%3 then condition should be assigned values 0, 1 or 2.

I’m trying to use your url and it’s awesome! However, I’m getting a 404 error when I try to actually implement it.
This is what I’m trying to do:

Are there specific aspects that need to be incorporated into the script itself that you’d recommend? Thank you very much!

You want

To get that link, use madlibs_fill_in_server/ instead of madlibs_fill_in_server

Alternatively, use my VESPR Study Portal, which is more powerful, even without the licenced features.

Thank you very much! This is an excellent tool and I appreciate your help.

That worked for me. Thank you!