Conditional reward in learning experiment

i am using Psychopy version 2021.2.3. i am trying to design a learning experiment in the builder view. i do have to give reward to participants when they press the correct keys. also each targets are given two different reward, according to the keys they press.
My design right now gives those conditional rewards even without the correct response. i have to give them negative points for each wrong responses too. now i have tried a couple of times to resolve the issue but i couldn’t find a solution.
I have created an excel file with the correct responses which is looped around the routine, as you can see in the screenshot. I’m also attaching an image of the excel for reference.

Any help would be appreciated since I’m new to psychopy and I have to get the experiment going soon.

Key presses are usually recorded in lower case so I would expect you to have a and l as in your ExpectedKey column.

Also, you seem to be setting the same variables in code and via a spreadsheet. You should probably choose one or the other.

What code are you using to “give” the rewards?

Thank you for your reply.
I have changed my key presses to lower case.

The code which i used for giving reward is,
in the begin routine:
if key_resp_3.keys == ‘a’:
Reward = “100”
if key_resp_3.keys == ‘l’
Reward = “50”
if not key_resp_3.keys:
Reward = “-10”

I have tried using this code and it doesn’t work. The experiment runs but neither the key_resp_3.keys nor the correct responses are stored in the data file. (nor reward is shown )

As a beginner in Psychopy, i am confused on how to go about coding for conditional rewards to correct responses and negative points for wrong responses. At the end of each block of trials i have to show the participants the total points scored and accuracy.

It would be of great help if you could figure a way out.
Thank you


Reward = '-10'
score -= 10
if key_resp_3.keys:
     if 'a' in key_resp_3.keys:
          Reward = '100'
          score += 100
     elif 'l' in key_resp_3.keys:
          Reward = '50'
          score += 50

It doesn’t look like you’ve got a separate feedback routine, so the above code probably needs to go into End Routine.

Also, if Reward is set in the spreadsheet and you actually care about whether they pressed the correct key rather than a/l then the following End Routine code might be better.

if key_resp_3.keys:
     if key_resp_3.corr:
          score += Reward
     score -= 10

This should give Reward points for the correct answer, zero for the wrong answer and -10 for no answer.
The assumed