Need to end loop immediately and not read routines

If this template helps then use it. If not then just delete and start from scratch.

OS Win10
PsychoPy version 2022.2.5
**Standard Standalone? y
What are you trying to achieve?: I have two sections of my experiment each containing several routines; I have programmed in a coin flip at the beginning of the experiment then set a routine inside the loop of both sections to refer to the coin flip. I am trying to use the coin flip to play either the first section first or the second section first depending on the coin flip.

What did you try to make it work?:
I have tried:

if coin_flip == 0:
         trials_12.finished = True

…I have also tried “continueRoutine = False”

What specifically went wrong when you tried that?:

It is stopping trials_12 from looping a second time but it is still reading through my routines for that first loop. Additionally, when I use continueRoutine = False it still reads the rest of the components in that routine over that first iteration, rather than terminating at that line of code. This is causing problems with populating one item from lists when later (after changing coin flip) and I DO want the routine to run, my list is now missing one item.

How can I get the routine/loop to stop dead in its tracks and proceed onto the next routine/loop??

Do you want the coin flip to select which loop to play?

If so, then set the number of repeats for trials_12 as coin_flip and the number of repeats for trials_21 as 1-coin_flip

I want the coin flip to decide the order of the loops, but I need both loops to play every time the experiment runs (5 times in a row each) before proceeding to the other one. I set the coin flip, then set the first loop with an if coin_flip is 0 skip it; then set the next section with a statement in a routine at the end saying if trials_6.thisN == 4 (the fifth cycle) to change the coin flip to 1 - coin flip so that then the first loop would play… the problem is it is reading my components on the ones it is “skipping.” I suppose I could try code_component.setAutoDraw(False) on the components that are populating images from my list? I just thought there might be a way to have more control…

By each time the experiment runs do you mean in each block?

I would do this with an outer loop than runs 5 times.

Within the outer loop you have the coin flip

Then a loop around your first section with nReps = coin_flip
Then a loop around your second section with nReps = 1
Then a loop around a repeat of your first section with nReps = 1- coin_flip

Basically the two sections are two different halves of the experiment (two separate experiments combined into one). I do like the repeat idea with the coin flilps–I have actually used that on a smaller scale with single routines I was trying to alternate between, but each half of the experiment has an extensive number of routines so I would have to duplicate a LOT in order to do that. But I think you are right, that is the best way!

For the second comment–yes I am trying to alternate A then B with B then A. Already within each half though I have alternated the order of restudy/practice-test based on the participant number, so I didn’t want to alternate the A/B order based on that as well or everyone with an even number would get A first AND restudy first…I was hoping the coin flip would randomize it to roughly half but on a different pattern than even/odd. Will the coin flip work that way or is it odd/even-based?

How are you creating your coin flip?

I randomise the order of test batteries using a master spreadsheet that looks like this:

In this case block_e has no 1s in it because the student dropped emotional Stroop and wanted numerical Stroop instead but I didn’t want to delete the work I’d done.

I had just used “coin_flip = random.choice([0, 1])” in a code component…

If you have a 2 x 2 design then what I would do is have four groups (based on participant % 4 if you are running locally or you could use the new counterbalance routine)

Then you can have rpAB, rpBA, prAB and prBA as your four groups.

Thank you very much for all of your help!!