| Reference | Downloads | Github

N-back task: present stimuli on x% of trials

macOS 10.13.4
PsychoPy v1.90.2
Standard Standalone

Goal: n-back task (2-back) with 8/48, or 16.67%, targets (2-back) and 40/48, or 83.33%, foils (other)

Current status: n-back task with the text, keyboard, and code components, looped with letters.csv–which works. I am having trouble presenting the letters stimuli a percentage of times. Below is the code from my code component. If anybody has any tips for how to present the variables of interest (two_back, letters) x percentage of times, I would be very thankful. Code (in “Begin Routine” tab) below:

# create n_back
if nback_trials.thisN == 0: 
    two_back = letters # initial value needed for trial 2
if nback_trials.thisN == 1:
    one_back = letters # need this to swap with two-back on later trials
if nback_trials.thisN > 2: # need to update the n-back values
    two_back = one_back
    one_back = letters

# response:
if letters == two_back:
    correct_response = '1'
    correct_response = '0'

*note: I have one_back = 'Not applicable' in the “Begin Experiment” tab to prevent initial breaking.