Randomization of several loops

OS : Win 10
PsychoPy version : v20201.3
**Standard Standalone? : y
What are you trying to achieve?:
My experiment does have 4 different loops until now. My goal is that those 4 different loops repeat themselves 3 times in a randomized order.

What did you try to make it work?:
I tried to create an randomized outer loop around the 4 inner loops and as well I tried to set up a conditions file for this outer loops. Both ideas did not work for me.

What specifically went wrong when you tried that?:
There is no error message. The experiment runs smoothly. But the randomization is missing.

Include pasted full error message if possible. “That didn’t work” is not enough information.

Are you trying to randomise the order of Start 1-4?

What you need is for them all to be dealt with using a single routine with parameters from the outer loop

Thank you for your reply!

Yes that is what I am trying to do as the routines differ slightly from each other.

If I understand it right I should create one single routine and specify the different parameters of every trial in the outer loop?

Again thank you for your help!

If the routines truly are different (ie they differ in ways that can’t be controlled just by using a conditions file (such as one routine playing a sound, while another shows an image), then you could control the order of the loops like this:


Nice but you don’t even need code.

The outer loop could connect to and Excel file with columns called e.g. Task1 Task2 with each row having a 1 in one column and a 0 in all the others.

For each task the nReps for the loop around it should be the corresponding column name.


Thanks a lot! Now it works.

I’m working on a very similar design but instead of four loops that need to be randomize, I only have one. I tried to do it exactly like you explained, creating an excel file with columns Task1 and Task 2 with rows 1 and 0 and then putting the column names for each nReps. However, the problem is that my first loop repeats 2x times and the second loop never appears. Do you have any idea of what is happening?


Please could you show some screen shots of of your loops and flow so we can see what you’ve done?

Best wishes,


thanks for the quick response!
Here are some screenshots of the experiment and how I tried to use your previous explanation.
Like you can see, my two loops have more than one routine(actually 3) because participants see the trial and then answer some questions referring to what they saw. The first loops(repeat1 and trials_5) around the 3 routines are controlling so that participants can move back and forth between the trials and questions.
For the randomization, I added other loops around(randomLoop and randomLoop2). I also added an outer loop that is connected to the excel file just like you explained.
Like I said, our problem is that the loop with the image trial repeats 2 times and then the experiment moves to the end page. That is, the text trial is not running.

According to outloop, general.xlsx only contains one row, so I would expect the two repeats to be identical. Shouldn’t it have two rows (if you want to randomise the order of Task1 and Task2), one with Task1= 0 and Task2 = 1 and one with Task1 = 1 and Task 2 = 0?

Sorry, but I don’t have much time to assist on these forums at the moment.

1 Like

Hey, I have another question on randomizing multiple routines.
I have 4 routines (instruction for task 1, task1, instruction for task 2, task). Now I want to randomize the order people see task 1 and 2 but the instructions should go before the tasks. So participant 1 should see: instruction task 1, task 1, instruction task 2, task 2. Participant 2: instruction task 2, task 2, instruction 1, task 1
Participant 3 same as Participant 1 and so on. How can I realise this for my online study?

You can have two loops that are both activated by the same variable or have an outer loop with Task1 as nReps that contains the instructions routine followed by a trials loop.

For alternating rather than random allocation I use group assignment in Qualtrics but you can also use my web app. https://moryscarter.com/vespr/pavlovia.php