Feedback with colored text

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

OS : Win10
PsychoPy version : 3.0.5
**Standard Standalone?: yes
What are you trying to achieve?:
I believe my problem should be relatively easy to solve. However, for whatever reason I cannot get my issue resolved myself. Basically, I want feedback that is a specific color based on whether the participant responded correctly or incorrectly.

What did you try to make it work?:
There are various resources online showing how to add feedback to a routine. After using the one provided on Psychopy’s website,

https://www.psychopy.org/recipes/builderFeedback.html

I managed to get my experiment to present “correct” or “incorrect” when the participant answers accordingly. To do this, I added a new routine after the main trial routine. This new routine contains a code component and a text component.
The text component contains $msg in the text box, and is set to every repeat. The code component has two elements:
Begin Experiment: msg=’ '.
Begin Routine:
if key_resp.corr:
msg=“correct”
else:
msg=“incorrect”

This works fine, but I want the correct text to be displayed in green, and the incorrect text to be displayed in red. How would I achieve this?

Hi @Steve_Pierzchajlo, set your color of your text component to a variable (e.g., msgColor), set that to update on every repeat, and add the following to the Begin routine tab:

if key_resp.corr:
    msg = "correct"
    msgColor = 'green'
else:
    msg = "incorrect"
    msgColor = 'red'

This worked! Thank you very much.

I did this, but it did not succeed. The program displays as follows:

correct1.setColor(msgColor, colorSpace=‘rgb’, log=False)
NameError: name ‘msgColor’ is not defined

And I don’t know why.
Looking forward to your reply

Having the colour set to be constant rather than update on every trial is usually the culprit here.

I have solved this problem. Thank you!

I would like to do the same. Is key_response generated automatically or is that a column in your excel? Newbie here. Thank you!