Correct Answer comparison in looping response

The issue here is what constitutes a “trial”. PsychoPy usually works on the idea that one row in the data file contains all the data pertaining to one trial. But the nature of your task is that one row in the data file is going to correspond to each response within a trial. Similarly, the correct answer variable must be specified at (and update for) the level of every individual response.

So check your posted .csv file. The first digit span is [1, 5, 7]. The corrAns column currently specified each of those as being the respective answer for that row of the file. But note that that cycle of presentation is completed before you start collecting responses. At that point, the value of corrAns is fixed at its last entry, which is why the only correct score you get is when you press 7 (and note that it would have been scored correct even if you typed that number out of order).

What you need to do is build up a list of correct answers during the presentation phase. And then during the response phase, you compare each answer to its corresponding entry in that list. Lets say you have a variable called correct_answers, which is [1, 5, 7]. Then in your keyboard component, the “Correct answer” field would be specified something like this:

$correct_answers[Response_Trial_Loop.thisN]

i.e. you index the list of answers by the current loop iteration number, so that in this case, 1 would be the correct answer for the first iteration (iteration 0), and 7 would now only be scored correct in the last iteration (iteration 2).

How to build the list? Something like this in the “Begin routine” tab of the code component in the “ExperimentTrials” routine, to initialise the loop as empty, and then grow it on each iteration with the current value:

if Experiment_Trial_Loop.thisN == 0:
    correct_answers = []

correct_answers.append(corrAns)

Note that you could also now use that list to set the number of iterations of your response loop. i.e. you could put something like this in the nReps field of the loop:

len(correct_answers)

instead of having to maintain some other variable (currently default_N).

You could probably also try de-selecting the “Is trials” option from the Experiment_Trial_Loop dialog, to stop it saving data. That would simplify the structure of your data file, as you aren’t really recording anything of interest there, just presenting stimuli. You would need to record the correct answer on each trial manually, though, then. Something like this in the “Begin routine” tab of the code component in the “Response_Trial_Routine”:

thisExp.addData('correct_response', correct_answers[Response_Trial_Loop.thisN])