Wrong feedback despite responding correctly

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

OS (e.g. Win10): Mac Ventura
PsychoPy version (e.g. 1.84.x): 2023.1.3
Standard Standalone? (y/n) If not then what?: y

What are you trying to achieve?: I have a reinforcement choice task with two different response options that are each associated with a specific stimulus (blue or yellow house). Participants will see a house (yellow or blue) on the screen and they have two options to choose from on the same screen: phone or bicycle. they should choose one of these two options by pressing the right or left key in a specific time (when a beep tone is being played). I give them feedback on whether their response was correct or incorrect after they press the correct key every trial (defined in my excel sheet). If they response correctly, they will see an “outcome” picture and then a text indicating the correct response, and if they response incorrectly, they will just see a “wrong response” text. I created two different loops for these.

What did you try to make it work?:
The strange thing is that the feedback-giving loops perfectly worked for me only a few times, but then stopped working!

Below is the flow of this part of my task:

And a screenshot of my data output file that shows the “Keypressed” or my keyboard component output is has not be recorded!


Below is a code component I added to “begin routine” in my routine:
correctReps = 0 #correct_loop feedback NReps
incorrectReps = 0 #correct_loop feedback NReps
trialCorrect = 0 #if the response was correct
keyToneDiff = ‘’
keypressTime = ‘’
keyPressed = ‘’

feedbackTxt = ‘’

Below is a code component I added to “each frame” in my routine:
if rightleft_choice_training.keys:
keyToneDiff = 1.2-t
keypressTime = tThisFlipGlobal

keyPressed = rightleft_choice_training.keys

rightleft_choice_training.keys = []

rightleft_choice_training.status = FINISHED

if keyPressed == correct:
    trialCorrect = 1
else:
    trialCorrect = 0

if keyToneDiff >= (0.1+frameTolerance):
    feedbackTxt = "Too soon!"
    timeFeedback.setAutoDraw(True)
    timeFeedback.status == STARTED
    timeFeedback.tStartRefresh = tThisFlipGlobal
elif keyToneDiff <= (-0.1-frameTolerance):
    feedbackTxt = "Too late!"
    timeFeedback.setAutoDraw(True)
    timeFeedback.status == STARTED
    timeFeedback.tStartRefresh = tThisFlipGlobal
else:
    if trialCorrect == 1:
        correctReps = 1
        points = points + 95
    else:
        incorrectReps = 1
        points = points - 5

Code components I added to my “correct_loop” routine for showing the outcome and giving feedback:
RL_outcome routine:
if trialCorrect == 0:
continueRoutine = False

RL_points routine:
if trialCorrect == 1:
outcome = “You chose the correct response. You volunteered today and gained +100 happiness points!”
else:
outcome = “Oh no, wrong answer! You don’t get to volunteer today! +0 happiness points.”
What specifically went wrong when you tried that?:
Explained above, but hypothetically: I think, by looking at the data. psychopy doesn’t recognise the keyboard inputs (or maybe the issue is with something else).

Code components I added to my “incorrect” routine for showing the outcome and giving feedback if the response was incorrect:
if rightleft_choice_training.corr:
outcome = “You chose the correct response. You volunteered today and gained +100 happiness points!”
else:
outcome = “Oh no, wrong answer! You don’t get to volunteer today! +0 happiness points.”

Include pasted full error message if possible. “That didn’t work” is not enough information.
I don’t get an error message, but the issue is despite responding correctly, I always get the “you responded incorrectly” (i.e., incorrect loop) feedback all the time. I worked for a strange limited time when I changed my loop name for correct responses from “correct” to “correct_loop” but stopped working again and gives me "outcome = “Oh no, wrong answer! You don’t get to volunteer today! +0 happiness points.”
" all the time!

I would be more than grateful if you help me spot the issue with not getting the correct feedback!

This is a part of the excel sheet in which the correct response for each trial is defined:

So based on this csv, psychopy should know whether ‘right’ or ‘left’ is correct (the correct column) for each trial.

right and left shouldn’t have quotes around them if you are using correct to define the correct answer for a keyboard component.

Thank you very much!