Giving feedback for four potential answers

Hi there,
I’m really new to Psychopy and coding. I’m creating an experiment whereby an arrow is displayed on top of an image, following which participants must use arrows on the keyboard to identify which direction the arrow is facing.
I want practice trials that give feedback after the participants have given their answer as to whether it is correct or incorrect. I have used the below code:

if key_resp_8 == corrAns:
     msg = 'Correct'
   msg = 'Sorry, Incorrect'

The error message I am seeing is ‘msg not defined’ and ‘corrAns isn’t defined’
I have defined msg in my text box and corrAns in my excel spreadsheet (see below);


Any help would be greatly appreciated



msg='doh!' #if this comes up we forgot to update the msg!

in a begin experiment tab.

then use

if not key_resp_8.keys :
    msg="Failed to respond"
elif key_resp_8.corr:
    msg = 'Correct'
    msg = 'Sorry, incorrect'

in the relevant begin tab.

See also here Builder - providing feedback — PsychoPy v2022.2.3

Best wishes Jens

Hi Jens,
Thank you for your help!
The problem I’m now facing is that the message ‘doh’ is displaying for the first trial and then for the subsequent trials, it seems that it is just randomly selecting which message to present rather than showing correct for correct answers and vice versa. I’m not sure if it is an issue with how I have laid my spreadsheet out? (see image above).

Thanks again,

Hello Caitlin

it might be that the order of the text-component and the code-component is wrong. The code-component has to appear before the text-component of the feedback message.

See the attached example.

Feedback.psyexp (12.5 KB)
loopTemplate1.xlsx (17.8 KB)

Best wishes Jens

It’s working!! Thank you so much :slight_smile:

Apologies! I decided to add more images to the experiment. I did not think this would impact my feedback loop. However, it is stating every answer is incorrect and I can’t see a reason why. I’ve changed nothing regarding the correct answer, merely added more images.
I really appreciate your help!

My spreadsheet also.


did you set corrAns in the response-key-component? Adding more stimuli does not impact the feedback.

BTW, initializing msg goes to the Begin Experiment tab. However, that shouldn‘t impact your feedback.

Best wishes Jens