N-back with Mind Wandering Probes

Hi all,

I set up a 1-back working memory task in the builder, and am trying to figure out the best way to randomize thought probes into the trials.

I currently have a routine, PracTrials, set up to pull from an excel sheet with columns $Trials and $CorrectResp along with a sequential loop, prac_loop, nReps $1. I also have two thought probes I’ve made into routines (TP1 & TP2), one with a slider component and the other with a textbox.

My question is: how do I interrupt PracTrials/prac_loop to randomly present TP1 or TP2 before going back to PracTrials? I’ve seen similar questions asked on the forum, and the response that got me closest to what I’m looking for involved a code component using an if statement like so:

if prac_loop.thisN in [7,21]
continueRoutine = False

so based off that I’m assuming that rather than stopping the loop at index 7 and 21, I need a code component to stop prac_loop randomly to display TP1 or TP2 (or if easier I have no problem setting TP to a fixed trial) before kicking back to PracTrial.

I’m more familiar with R than Python so I can follow concepts well enough, I’m just unfamiliar with specific syntax. Any advice on how to complete the above or suggestions on a cleaner flow would be very appreciated, thanks so much!

You might find my prospective memory N-Back task useful since it inserts memory probes. I preload the stimuli and randomly insert the n-back trials and the PM targets (with constraints).

PM N-Back code | try it

I have been writing prospective memory experiments for students for over 20 years. Most have had a lexical decision ongoing task, but this one has a lexical n-back task instead. The repeated items are randomly inserted rather than using a pre-determined sequential order.