# Randomize two loops with different routine structures

OS (e.g. Win10): macOS Big Sur Version 11.6
PsychoPy version (e.g. 1.84.x): 2021.1.2

What are you trying to achieve?:
I have two loops that surround two different sets of routines (entitled “difficult_block” and “easy_block”). I want to randomize the presentation of these loops such that the “difficult_block” routine set is presented 5 times and the “easy_block” routines are presented 5 times in any random order. In addition to randomizing the loops, I also don’t want any repeat trials within the loops - I would like to pull from my referenced files randomly without replacement.

What did you try to make it work?:
I’ll be completely honest in saying I do not know really anything about coding, but I tried to follow the directions from the last post on this webpage (Random routines - #10 by Leonardo_Venturoso).

More specifically:

-Under my “randomize_blocks” loop I have set nReps to 10.
-Under my “difficult_block” loop I have set nReps to orders[0][randomize_blocks.thisN]
-Under my “easy_block” loop I have set nReps to orders[1][randomize_blocks.thisN]

I have also created a code component under the “Instruct_Dff” routine under “begin experiment”:
“orders = [[1,0], [1,0], [1,0], [1,0], [1,0], [0,1], [0,1], [0,1], [0,1], [0,1]]
shuffle(orders)”

When I try to run this, the “difficult_block” seems to be continually presented.

Any recommendations are very appreciated! Thank you!

Hello

nReps determines how often your stimuli are repeated! So nReps = 5 repeats all your stimuli 5-times. Do you intend that? If not, use nReps = 1

Best wishes Jens

Thank you so much for your response! I have played around with altering the nReps number under “randomize_blocks”. If I set it to 2 using the code above, I get one iteration of the “Easy_Block” loop and one iteration of the “difficult_block” loop. If I bump up the nReps to anything above 2 I get an error:

“block = data.TrialHandler(nReps=asarray(orders[0][randomize_blocks.thisN]), method=‘random’,
IndexError: list index out of range”

I would like 5 iterations of the easy block and 5 iterations of the difficult block in a random order (e.g. easy, difficult, difficult, easy…etc), but I cannot get past the program only demonstrating one of each before the error now.

I think something must be wrong with my code? Unfortunately, I do not know how to code and have only been working off of what I have seen on other posts.

Hello

are easy and difficult block basically the same and differ only in difficulty?

Best wishes Jens

Hi Jens,

They are actually a bit different. The difficult block offers conditional feedback to math problems as well a graphical image that presents a fake scenario of how the individual is doing in comparison to other participants. The easy block offers no feedback and no graphical image. The participants are just doing math problems in their head and are told to press a button when they have solved the problem.

That sounds pretty similar. If you put all the conditions in one spreadsheet you could use code to skip the bits you don’t want in the easy condition.

For skipping images I sometimes present a transparent png. It’s a way of presenting nothing without using code. Could you use a similar method to not present the scenario?

Hello,

as wakecarter said, the routines are similar. You could realise everything in one routine simplyfing the loop construction.

Excel-sheet
condition feedback picture
simple 0 null.png
simple 0 null.png
difficult 1 graph.png
difficult 1 graph.png

Run the feedback-routine only when feedback == 1

Best wishes Jens