psychopy.org | Reference | Downloads | Github

Feedback depending on correctness of answer inside a trial

feedback

#1

Hi everyone,

What are you trying to achieve?:
I am programming an IAT, where participants have to categorize stimuli (left vs right). Here is a simplified version of the experiment so there is only the relevant stuff.
My goal is the following :

  • if the participant answers correctly, the experiment must continue to the next trial.
  • if they answer incorrectly, feedback appears (eg: a red cross), and they should correct their answer by hitting the other key. My dependent variables will be the RT of the correct answers, but I would like to have the RT of the wrong answers as well.
    That implies a few functionalities I am struggling with.

1. How to give the feedback inside the trial ? (I am able to create adequate feedback with a custom Code but only outside of the trial, hence not giving the possibility to correct the answer)
Here is the code I use :
Begin experiment
msg=""
Begin routine
if resp.corr==1:
msg=""
else:
msg=“X”

Now, the problem is that all resp.corr are registered as “0” in the data file, and thus logically, irrelevant of the answer, the feedback is always “X”. What strikes me is that I did not change the “resp” component, and when the same code was in another routine (after the trial), the encoding of resp.corr worked just fine.
Also, already at the first occurence of the stimuli, a feedback appeared even though no keys were pressed.
I guess it’s an easy one but I have no clue.
(I have read How to provide simultaneous feedback? but I am not skilled enough to adapt it to my case)

2. How to end the trial only if the given answer is correct ?
Since I am blocked at step 1/ I cannot test it already but I plan to untick Force end of routine in the keyboard component, ask to Store all keys, and add in the code Each frame :
if resp.corr==1:
continueRoutine = True # end this trial and continue with the next one
elif:
continueRoutine = False # end this trial

according to the solution shared here

A huge thanks in advance for your time and pedagogy,
Youri

(I am using Win10 and v1.90.1)


#2

This is because you can only check for the correctness of a response after it has been made. So this code will work in the “Begin routine” tab of a routine that comes after the routine in which the response is made. But it can’t work in that tab in the routine where the response is made, because the response hasn’t occurred yet.

To fix the issue, simply shift your check from the “Begin routine” tab to the “End routine” tab. Make sense?


#3

Thanks for your sensible advice, it works perfectly !

However, I am now facing problems with step 2/.

  • if I choose Force end of routine in resp, the trial finishes (and the feedback appears correctly but there is not possibility to correct the answer)
  • if I don’t choose it, nothing happens whatever the correctness of the answer

#4

Sorry, I missed that other part of your question (about not ending the routine in response to an incorrect answer).

In this case, the code can’t go in the “End routine” tab either. We need to put code in the “Each frame” tab, so that the keyboard is being continuously monitored. If a correct response occurs, then we end the routine. If it is incorrect, do nothing, and allow the routine to continue. So:

  • De-select the “Force end of routine” setting in your keyboard component. You’ll have to use code to decide when the routine ends.
  • Set the “Store” option to “All keys” so that each response is recorded.
  • In the “Each frame” tab, put something like this:
if resp.corr:
    continueRoutine = False

Actually, re-reading your post above,. I think you had already proposed this solution yourself.


#5

That’s what I’ve been trying, yet unsuccessfully.
When I De-select “Force end of routine”, nothing happens when I set the “Store” option to “all keys”. I assume that is because no answer is considered as correct.
I tried to set it as “first”, and it works fine until a given answer is wrong, and then nothing happens (which is logical).
When it’s set as “last”, no feedback appears when the answer is wrong, but it goes to the next trial (which is logical as well). This situation is the closest to what I would like to achieve but still not satisfying.
Based on these observations, I suspect that the problem is in the way the keys are recorded.
I tried in the Frame tab :
if resp.corr[-1]==1:
continueRoutine = False
but I was nothing but disappointed.

(I just realized I quoted the you from 2015 ! :slight_smile: )
Best,


#6

OK, I should look into the code in detail to see how the keyboard component handles this with each of these settings, but I’ll just try guessing instead: I think we could do something like this to check if the response is correct (slightly modifying the code you suggest):

(I’m guessing from the screenshot above that the variable in your conditions file that gives the correct value is called Reponse):

if resp.keys: # ie if the list isn't empty:
    if resp.keys[-1] == Reponse: # check the latest response
        continueRoutine = False # end if it is correct

Again, keep “Force end routine” unselected.


#7

Sorry, I’ll give all the details.

Here are the files I am using :
MascFem.xlsx (8.8 KB) (The external list)
Test.psyexp (12.3 KB) (The script of the experiment)

Here is the keyboard component :

Here is the code I used :

  • Begin experiment
    msg=""

  • Each frame

if resp.keys: # ie if the list isn't empty:
    if resp.keys[-1] != Reponse: # check the latest response
        msg="X"
    elif resp.keys[-1] == Reponse: # check the latest response
        continueRoutine = False #"

What happens in the data file is that resp.corr is always zero.
The feedback for the wrong answers only appears when the correct answer is given.
If a wrong answer has been given once, the feedback will appear even for trials where no wrong answer was given.


#8

I think you’d already found that this doesn’t work correctly when multiple responses are allowed, so perhaps you should just set this value manually, as below:

if resp.keys: # ie if the list isn't empty:
    if resp.keys[-1] != Reponse: # check the latest response
        msg = 'X'
    else:
        resp.corr = True # set this manually
        continueRoutine = False #"

I guess that means that you are showing it on the next routine? If you want it available on the current routine, then $msg would need to be put in a text field on the current routine, and importantly, set to update on every screen refresh, so that any change will be seen immediately.

That is because you are doing this:

msg = ''

Only once, at the beginning of the experiment. That code needs to be in the “begin routine” tab of the routine where you collect the responses, so that it gets reset at the beginning of every trial.

The common thread here is getting your head around when the code in each tab is executed, relative to the events in your trial. Things that are constant throughout the session get set at “begin experiment”. Things that need to be done just once per trial get done either at “Begin routine” or “end routine” as required. And things that need to be updatable at any point within a trial get executed at “every frame”. Your stimuli fields need to be set to update in the same way (ie to be constant, to update once per trial, or every refresh). And make sure that the code component is placed above any stimuli that need to access its variables, so that they can refer to the latest value.