Incorrect Feedback response after the trial

Hi all,

I am trying to create an experiment where a respondent has to make a choice of selecting the choices of a modified Dilemma case. The problem I am having is when presented with the three options (Steal, leave or split), whenever a respondent chooses the response, the system is unable to pick from the responses and provide coherent feedback. I think it is not even leaving the first If loop, and is responding with either the first correct choice or the first incorrect choice. It is completely ignoring the responses with selecting second or third choice. I am making some primitive error in nested-if, but welp, here I am!

I would like to have the feedback that when the respondent selects ‘1’ and the correct answer is ‘1’, it gives the corresponding correct feedback, and if it is incorrect, then it provide the corresponding incorrect feedback. Where am I going wrong in the code?

The code is attached herewith:

msg=''
keys = event.getKeys()
corr = PDCKey.corr

if keys:
    if corr==1 and corr!=2 and corr!=3:
        TextColor = 'green'
        msg = 'Yes! You both stole, thus you both win nothing! Thieves!'
    elif corr!=1:
        TextColor = 'red'
        msg = 'No! You stole but computer did not steal, and hence you lose all the money! Idiot!'
    if corr==2 and corr!=1 and corr!=3:
        TextColor = 'green'
        msg = 'Yes! You both gave away, thus nobody wins anything! Cowards!'
    elif corr!=2:
        TextColor = 'red'
        msg = 'No! You gave away your money but computer did not, so computer took away all your money! Generous loser!'
    if corr==3 and corr!=1 and corr!=2:
        TextColor = 'green'
        msg = 'Yes! You both split, you both get half of the money!'
    elif corr!=3:
        TextColor = 'red'
        msg = 'No! You split, but computer did not, but since you were generous, you get your share!'

Thanks in advance!

Hi there, I’m going on the fly with writing the code based on my understanding on what you want to do here - and assuming you have a column in your excel sheet with the correct answer with the header names corrAns

msg=''
#keys = event.getKeys() # for my proposed code, you do not need this line
#corr = PDCKey.corr # this line is also not necessary. and corr is a boolean value which is why I think it's skipping your elif statements with 2 and 3

if PDCKey.keys == corrAns and PDCKey.keys == 1: #comparing which key is pressed with the correct answer for that trial and if the key pressed was 1
        TextColor = 'green'
        msg = 'Yes! You both stole, thus you both win nothing! Thieves!'
elif PDCKey.keys != corrAns and PDCKey.keys != 1: #if the key pressed is not the same with the correct answer for that trial and if the key pressed was either 2 or 3
        TextColor = 'red'
        msg = 'No! You stole but computer did not steal, and hence you lose all the money! Idiot!'
elif PDCKey.keys == corrAns and PDCKey.keys == 2:
        TextColor = 'green'
        msg = 'Yes! You both gave away, thus nobody wins anything! Cowards!'
elif PDCKey.keys != corrAns and PDCKey.keys != 2:
        TextColor = 'red'
        msg = 'No! You gave away your money but computer did not, so computer took away all your money! Generous loser!'
elif PDCKey.keys == corrAns and PDCKey.keys == 3:
        TextColor = 'green'
        msg = 'Yes! You both split, you both get half of the money!'
elif PDCKey.keys != corrAns and PDCKey.keys != 3:
        TextColor = 'red'
        msg = 'No! You split, but computer did not, but since you were generous, you get your share!'

Hi @suelynnmah ,

Thank you for your response. Unfortunately, it didn’t quite do the job.

Every feedback of the response is selecting this as the feedback, and running only this block of code:

At every correct as well as incorrect response from the respondent (Even for 1 as the correct choice).

This is the excel sheet of stimulus:

And this is how my experiment looks:

Is there something else that is wrong? Thanks again!

Hello,

you don’t seem to have a key-component (PDCKey) in your routine, at least not in the one routine you present.

Best wishes Jens

Apologies. This is the routine just before the feedback routine (The routine where the choice is made, with the keyboard allowed keys are 1,2 and 3).

Hello,

did you check Store Correct an the Data tab of the keyboard-component and set the variable?
You could add a print command before your if-else construction to check the values of the respective variables.

print("PDCkey: ", PDCkey.keys)
print("correct: ", corrAns)

Best wishes Jens

Hi @Jens,

This is providing both the correct input and the correct answer. I think the problem is in the if loop, or probably the conversion of the list, but I can’t be too sure.

Hello,

when you only care about the correctness of the response and not which key is pressed, you can simplify your if-else construction:

if corrAns:
    msg = "correct"
    TextColor = "green"
else:
    msg = "wrong"
   TextColor = "red"

If you want to consider the key, try the following:

if corrAns:
   TextColor = "green"
   if PDCkey.keys == '1':
        msg = "correct 1"
    elif PCDkey.keys == '2':
        msg = "correct 2"
    elif PDCkey.keys == '3':
        msg = "incorrect 3"
else:
   TextColor = "red"
    if PDCkey.keys == '1':
        msg = "incorrect 1"
    elif PCDkey.keys == '2':
        msg = "incorrect 2"
    elif PDCkey.keys == '3':
        msg = "incorrect 3"

Notice that PDCkey.keys is a string not an integer, so surround it with '.

Best wishes Jens

1 Like

Hi @JensBoelte ,

Half of the problem is solved. Thank you!

What I mean is, when I run this code, irrespective of correct or irrespective response, it is running only this block of code:

In incorrect consideration also, it is providing the feedback of the pressed key from the correct code.

Here is my version for your reference:

msg=''
#keys = event.getKeys()
#corr = PDCKey.corr

#print("PDCKey: ", PDCKey.keys)
#print("correct: ", corrAns)

if corrAns:
    TextColor = "green"
    if PDCKey.keys == '1':
        msg = "Yes! You both stole, thus you both win nothing! Thieves!"
    elif PDCKey.keys == '2':
        msg = "Yes! You both gave away, thus nobody wins anything! Cowards!"
    elif PDCKey.keys == '3':
        msg = "Yes! You both split, you both get half of the money!"
else:
    TextColor = "red"
    if PDCKey.keys == '1':
        msg = "No! You stole but computer did not steal, and hence you lose all the money! Idiot!"
    elif PDCKey.keys == '2':
        msg = "No! You gave away your money but computer did not, so computer took away all your money! Generous loser!"
    elif PDCKey.keys == '3':
        msg = "No! You split, but computer did not, but since you were generous, you get your share!"

Hello,

ok, do you understand you correctly? The part of the else-part is never executed? What happens if you change this part of the code to

elif not corrAns:

Best wishes Jens

Hello @JensBoelte ,

Yes, you understood correctly, but unfortunately that didn’t work.

Also, I tried modifying your code to this in a separate window, and that change neglected the if and ran the else code (Irrespective of correct or incorrect response).

if PDCKey.keys == corrAns:
    TextColor = "green"
    if PDCKey.keys == '1':
        msg = "Yes! You both stole, thus you both win nothing! Thieves!"
    elif PDCKey.keys == '2':
        msg = "Yes! You both gave away, thus nobody wins anything! Cowards!"
    elif PDCKey.keys == '3':
        msg = "Yes! You both split, you both get half of the money!"
elif PDCKey.keys != corrAns:
    TextColor = "red"
    if PDCKey.keys == '1':
        msg = "No! You stole but computer did not steal, and hence you lose all the money! Idiot!"
    elif PDCKey.keys == '2':
        msg = "No! You gave away your money but computer did not, so computer took away all your money! Generous loser!"
    elif PDCKey.keys == '3':
        msg = "No! You split, but computer did not, but since you were generous, you get your share!"

This is my modified code:

I assume the answer is somewhere in the middle.

Hello,

sorry my fault. corrAns will always have a value (1,2 or 3) so it will always be true. You need

if PDCKey.corr:
....
elif not PDCKey.corr:

Best wishes Jens

2 Likes

That did it! Thank you so much @JensBoelte !!