Correct and incorrect feedback error message with code

6.3147 WARNING User requested fullscreen with size [1024 768], but screen is actually [1920, 1080]. Using actual size
1.6063 WARNING Monitor specification not found. Creating a temporary one…
File “C:\Users\Zelal Sila\Documents\DRLLearning\experiment_lastrun.py”, line 572, in
if key_resp.key[1]==corrAns:
AttributeError: ‘Keyboard’ object has no attribute ‘key’
################# Experiment ended with exit code 1 [pid:5964] #################
7862.0705 INFO Loaded monitor calibration from [‘2023_01_12 18:45’]

I tried to add performance eedback at end of each trial, basically correct or incorrect. However I am getting this error message.

I added this code in the end routine in the trial routine.

if key_resp.key[1]==corrAns:
correct = 1
else :
correct = 0
thisExp.addData (‘correct_answer’ , correct)

I also added this in a separate this in a separate routine.

in begin experiment:

msg = ‘’

and this in Begin routine

if correct == 1:
msg = ‘Correct’
else:
msg = ‘Incorrect’
if incorrect == 1:
msg = ‘Incorrect’
else:
msg = ‘Correct’

Please may you help? Thanks

Hello,

there is no need to check whether key_resp.keys equals corrAns. Try the following approach

if not key_resp.keys:
    msg="Failed to respond"
elif key_resp.corr: 
    msg='Correct'
else:   
    msg='Incorrect'

You need a column in your Excel-file which codes the correct answer, here corrAns, and provide the column name in the key_resp property (see below).

If you tick the Store correct box, PsychoPy stores the correctness of the answer (0,1) in your result-file (see picture above).

The code to determine the msg should follow the response and appear before the feedback is displayed.

Best wishes Jens

1 Like

Thank you. which part do I add this too? begin routine
?

Hello,

see here the flow of a toy-experiment and the make-up of the feedback-routine.

The code goes in the begin routine tab of the feedback-routine. The feedback-routine follows the RT-routine.

Best wishes Jens

1 Like

Thank you very much

I need to display the following messages

'correct, it was associated with a reward + 10

correct it was associated with a punishment -10

incorrect it was associated with a reward + 10

incorrect it was associated with a punishment -10

Can I add these as else in the code?

Thank you for your help

Hello Zelal

yes, this is possible. What determines the different rewards and punishments?

Best wishes Jens

Two image files, a and b, sometimes A is associated with a reward or punishment. Likewise, B is sometimes associated with a reward or punishment. I also need to accumulate points, but I haven’t
gotten that far yet.

A punishment is -10 and Reward is + 10
Best wishes

Zelal

Hello Zelal

well, how do you to determine that A is associated with a reward or a punishment? Random, specific distribution (10% punishment, 90% reward), 50:50? Do you specify this in advance in an Excel-file?

Best wishes Jens

1 Like

Yes, exactly; I specify the contingencies in reward or punishment in the conditions files, excluding the points. And this conditions file is inserted into the Loop.

Hello Zelal,

do you mind posting a toy-example of your Excel-file containing the contingencies?

Best wishes Jens

1 Like

(post deleted by author)

Hello Zelal

you need to explain to me in more detail what the columns mean. I know nothing about your experiment.

corrAns = the correct key
Feedback_1 = ???
key_respkeys = ???
Correct = reward ?
Incorrect = punishment ?

What determine that the correct answer gets punished or rewarded?

Best wishes Jens

corrAns= correct key

I created these while trying to figure out how to provide feedback as mentioned above and the accumulated points which would display after feedback.

Feedback1 = this has no function
Correct has no function
Incorrect has no function

Thank you for your patients.

Feedback1 is actually the points received based on correct responses. But I have taken this component out.

corrAns= correct key

I created these while trying to figure out how to provide feedback as mentioned above and the accumulated points which would display after feedback.

Correct has no function
Incorrect has no function

Thank you for your patients.

Hello Zelal

you wrote

When you want these four reward-contingencies you need a condition upon which the value of the reward/punishment is determined. Whether an answer is correct or incorrect can be determined by key you specify in corrAns.

Best wishes Jens

Hello Jens

I made two columns for correct points and incorrect points. For the each contingency condition, do I need to add a column with the corresponding points


?

Blockquote

Hello

ok, a correct response to r always gets 10 points, a correct answer to p gets -10 points, an incorrect answer to r or p gets 0 points, right?

So, it is only three conditions not four. A simple way would be the following

if not key_resp.keys:
    msg="You failed to respond"
elif key_resp.corr: 
    if corrAns == 'r':
        msg='Correct. You earned 10 points.'
    elif corrAns == 'p':
        msg='Correct. You earned -10 points.'
else:   
    msg='Incorrect. Your earned 0 points'

In case you want to use the values provided in columns, use the following:

if not key_resp.keys:
    msg="You failed to respond"
elif key_resp.corr: 
    msg = "Correct. You earned " + str(Correctpoints) + " points."
else:   
    msg="Incorrect. Your earned " + str(Incorrectpoints) + " points."

Best wishes Jens