AX-CPT (AX Continuous Performance) Task in fMRI

Hi all,

As a newcomer to PsychoPy- I am trying to build a AX-CPT task in builder, in the task one has to press a response button when the target letter X appears followed by letter A. I am interested to use the task in fMRI settings. To make it work I tried to use loopType: Sequential and nReps: 10 in the trial properties. This way I get X followed by A but the order of all the letters (A, B, C, X, Y etc.) will of course be the same on every repetition. When I try to use the randomisation option I cannot get X followed by A.
I saw a previous post on the same topic

and tried to use this code:

In "Begin Experiment" :
prevA = False

in "Begin Routine":
if prevA and text == 'X':
    corrAns = 'space'
    corrAns ='none'

in "End Routine" :
prevA = False
if text == 'A':
    prevA = True

Using this code, it doesn’t show the correct response option in the data file corrAX or response button (e.g. ‘spacebar’) in condition file.

Could anyone suggest how to properly design the trials so that one gets X followed by A on every repetition in a randomised order?

Thanks in advance for your valuable input.