Insert probe randomly, but then finish the rest of the trials in a block

OS: macOS Monterey 12.3.1
PsychoPy version: 2021.2.3

What are you trying to achieve?:
I have a task where participants are instructed to press the space bar in sync with a metronome tone (one tone/space bar press is one trial). The final task will have 18 blocks of 50 trials. I would like to randomly insert three probes indexing attention, affect, and arousal (in that order) somewhere between trial 35 to 50 (inclusive). However, once the probes show up I would like the participant to finish the remaining trials before starting the next block (e.g., if the probe shows up after trial 40, I would like the participant to finish trials 41 to 50 before starting the next block of 50 trials).

What did you try to make it work?:
I currently have one routine labelled “mrt” that contains the tone. The sound is housed in an Excel file and is set to every repeat. I then have a routine labelled “probing” that contains custom code. Both of these routines are in a loop called “expTrial” where nReps is 1 and the selected rows from the Excel file are 0:51.

The before experiment code in “probing” is:

trialNumbers = list(range(35, 51))

And the begin routine code in “probing” is (I’ve also tried expTrial.thisRepN in place of expTrial.thisN with no luck):

if expTrial.thisN == random.choice(trialNumbers):
    continueRoutine = False

Following the expTrial loop, I have 3 routines (one for each probe) as images called “thoughtProbe”, “affectProbe”, “arousalProbe”. Each routine (i.e., probe) has a keyboard response to move to the next routine/probe. The “mrt” routine, “probing” routine, and 3 image probe routines are all in a loop with nReps == 18.

What specifically went wrong when you tried that?:
So far it “works” in the sense that after 50 trials the attention, affect, and arousal probes show up before moving on to the next 50 trials but I am unsure as to how to randomly insert these probes and then continue with the remaining trials before moving onto the next 50.

I’ve also did some digging around on some other posts to try and find some code that may work for my experiment but so far I have found nothing.

Thank you!

Edit: attached photo

Hi @tbkruger,

Thanks for your post!

Just to clarify, do you want one of each probe (thought/affect/arousalProbe) routine to appear randomly in each of the 18 blocks, somewhere between trials 35-50? If so, these routines need to be within your expTrial loop. The way you’ve got things set up here means that you’re only skipping the probing routine (which if I understand correctly only contains code components?) that will be skipped on the trial set by random.choice(trialNumbers).

Are you able to upload your .psyexp file here for me to take a look at?