Storing response on a correct trial

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10):
PsychoPy version (e.g. 1.84.x):
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
Hello I am trying to store a correct response in the results excel sheet. The program goes through a loop showing an image on each loop. The participant has to respond on the correct image. For example the loop is called trials_2 and currently psychopy stores a number for each iteration of the loop 0,1,2,3,4. I know that the correct answer is on the 3rd iteration of the loop.
What did you try to make it work?:
What I have tried in a number of different ways is adding code component into the routine within the loop (the loop only surrounds one routine). In this code component I tried something like this:
if trials_2==3 and key_resp_2 != None:
key_resp_2.corr=1

then after the loop ends I put a code component in later routine with somethign like:
if key_resp_2.corr != None:
trials.addData(‘Correct Hit’, 1)
else:
trials.addData(‘Correct Hit’, 0)

What specifically went wrong when you tried that?:
This method does not work. There is currently no streamlined way of doing this in psychopy. I think a future model of psychopy would do well with a feature in the loop section settings where you can mark correct trials and it stores the data. For now though I am quite clueless how to implement this effectively. Thank you for your help and if need be I have attached my project file.
HL_ensemble_prestim.psyexp (2.5 KB)
Include pasted full error message if possible. “That didn’t work” is not enough information.

If you have a correct answer set on your keyboard component, then any correct answer given should be stored in a column key_resp_2.corr in your data output. Are you trying to only store this on the third trial in the loop? In which case you could set key_resp_2.corr to equal 0 via the Each Frame tab when not in the third iteration of the loop - meaning any response is wrong

I fixed this issue myself - what I needed to do was store correct answers into one excel file and then nest the excel file within another excel file. I can’t explain it very well but this is how I figured out how to do it. https://www.psychopy.org/builder/blocksCounterbalance.html#blocking

very useful to anyone trying to set up multiple loops the way I did and store correct answers within both loops.