Data not saving correctly from scored trial within a loop

PsychoPy version: v2022.2.5

The task is to choose between two pictures after an audio cue. Correct choices are scored as “1” and incorrect choices are scored as “0”. There are a total of 6 trials, but after 3 trials, I would like an image to be shown for 2 seconds then have the participant answer a question about the image–this is to check if they are paying attention. I would like the trial to be scored, where “1” would be the correct answer and “0” is the incorrect answer.

This is currently what I’m working with. The participants are shown the two images for the experimental trials in “testing” and then asked to choose one of the images in “choiceTest”. After 3 trials, they are shown an image in “unicorn2” for 2 seconds before being asked to click one of two texts in “familiarity2”. The final 3 trials would play until the last trial is done.

The routine and coding of “familiarity2” is as follows. Participants can either click “elephant” or “wolf”. Clicking “elephant” is the correct answer that I would like to be scored as “1”. “Wolf” would be scored as 0.

#In Begin Routine
if testingLoop.thisTrialN != 2:

#In End Routine
if wolf.contains(clickchoice4):
    thisExp.addData ('RT', t)
    thisExp.addData('clicked', "wolf")
    score = 0
    thisExp.addData('score', score)
elif elephant.contains(clickchoice4):
    thisExp.addData ('RT', t)
    thisExp.addData('clicked', "elephant")
    score = 1
    thisExp.addData('score', score)

This is what I get for the output: jktest39_WW_1_kids_2023-09-12_15h33.16.522.csv (12.1 KB). The first 3 trials and the attention trial scores correctly, but then the trials after the attention trials are not scored.