Creating a scored attention trial within an existing 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 32 trials, but after 16 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 16 trials, they are shown an image in “unicorn2” for 2 seconds before being asked to click one of two texts in “familiarity2”. The final 16 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 != 15:
        continueRoutine=False

In Each Frame:

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

My issue is with the .csv file that is generated after the experiment (see jktest13_WW_1_kids_2023-09-05_16h40.10.209.csv (35.4 KB). The scored attention trial is on the same row as one of my test trials instead of on its own. Also, the test trials afterward are scored but the label in “clicked” just says what I choice in the attention trial and not the picture clicked in each test trial.

I have tried to put an additional row into the spreadsheet that has the test trials in order, but that does not solve the problem.

Hello,
In your attention trial, did you try moving to the next row at the beginning of the routine?

# Begin Routine
thisExp.nextEntry()

Chen

I tried putting that code into the attention trial (“unicorn2” and “familiarity2”) but it coded the response in pairs with the rest of my trials and didn’t give it a score (see
jktest14_WW_1_kids_2023-09-07_13h09.15.360.csv (64.8 KB)).

Where did you put the code?
Can you please share your code component in full?

Something like the following should work:

# Begin Routine:
if testingLoop.thisTrialN != 15:
    continueRoutine=False
else:
    thisExp.nextEntry()

Also, you wrote that you included the code at the beginning of the experiment. Did you mean the beginning of the routine?

Yes, sorry, I put it in Begin Routine (I edited the original post).

This is the code I just tried. I put it in the routine “familiarity2” and received this output -
jktest17_WW_1_kids_2023-09-07_14h40.46.089.csv (33.2 KB). This scored each trial but didn’t code the clicked picture or reaction time correctly for any experimental trial.

#In Begin Routine
if testingLoop.thisTrialN != 15:
    continueRoutine=False
else:
    thisExp.nextEntry()

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

Previously I put the code that was in “Begin Routine” in “Each Frame”, which gave this output -
jktest16_WW_1_kids_2023-09-07_14h30.56.579.csv (112.8 KB). This gave many duplicates of one trial (the one right before the attention trial) and did not score the attention trial.

An update:

I realized it wasn’t coding the attention trial because I put it in the wrong column, however I am still having issues. With the code below, the experimental trials after the attention trial are not correctly storing the clicked picture (in column “clicked”) or the reaction time (in column "RT). It is storing “elephant”, which is the input from the attention trial, and not the data from the experimental trials. See:
jktest27_WW_1_kids_2023-09-07_16h29.38.819.csv (12.0 KB).

##In routine "familiarity2"
#In Begin Routine
if testingLoop.thisTrialN != 2:
    continueRoutine=False
else:
    thisExp.nextEntry()

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

The number in the first line of “Begin Routine” code changed from 15 to 2 because I decreased the number of experimental trials to 6 (3 trials before the attention trial and 3 trials after) so I could test this code quicker.