Providing per trial feedback using a code component

Thank you in advance for your patience and help!

OS (Mac Big Sur)
PsychoPy version (e.g. 2021.1):
**Standard Standalone? y
What are you trying to achieve?:

I am trying to run a half Simon. This means that participants should respond to arrows that point to the right regardless of their position. And they should not respond at all to arrows that appear on the left. I am attaching my stimulus control file.

I wish to show the message correct, when the key that has been pressed matches the correct response. And the message, “incorrect” when the key that has been pressed does not match the correct response. This is relatively easy and I have it working thus:

if not practiceresp.keys :
    msg="Too Slow"
elif practiceresp.corr:#stored on last run routine
    msg="Correct!" 
else:
    msg="Incorrect"
    
    

However, sometimes the correct response is to do nothing, in which case when these conditions are met I would like the message to be displayed as, “correct” and not as, “too slow.” I have included the correct response for these conditions in my stimulus control file as “none” To try and resolve this I have written:

if not practiceresp.keys and practiceresp.corr is not "none"  :
    msg="Too Slow" 
elif practiceresp.corr:#stored on last run routine
    msg="Correct!" 
else:
    msg="Incorrect"
    
    

However, all of this is not looking as expected, I now get the message, “too slow” after every single trial.

halfprac.csv (123 Bytes)

Hi There,

I think you are very close.

if not practiceresp.keys and resp is not "none"  :
    msg="Too Slow" 
elif practiceresp.corr:#stored on last run routine
    msg="Correct!" 
else:
    msg="Incorrect"

How does this work?

Becca

Thank you so much! Unfortunately this did work as I was expecting either. The thing is that if the practice response keys contains nothing the message too slow should be displayed. The only exception for this should be is the correct response is none. Running the code as you have written it provides an error, namely that, “response is not defined”.

I then tried following your logic but changing the variable names so that they match. And then I got:

if not practiceresp.keys and practiceresp is not "none"  :
    msg="Too Slow" 
elif practiceresp.corr:#stored on last run routine
    msg="Correct!" 
else:
    msg="Incorrect"

However, I still get the message too slow for every single trial. It should only be displayed when the correct response is not none and no key has been pressed. Then, if they are correct response is either nine or it has just been pressed, the message should be, “correct” otherwise, incorrect. That’s incorrect should be displayed if the correct response is not non-and the correct response has not just been made. I hope this makes at least a little sense?

I have the encouraging,- but extremely frustrating,- feeling that I’m very close to getting this to work! :slight_smile:

“response is not defined” - where in your code did you use “response” is there a chance you used “response” accidentally instead of “resp”? (I used resp seeing that was the name of your column header in your conditions file?)

I think it could also be that you need a capital N in your "none"s

Here is a demo file that should help with what you want the feedback will be 0 (incorrect) or 1 (correct) and none responses are also coded as correct or incorrect.

halfprac.csv (177 Bytes) check-none-response.psyexp (10.3 KB)

hope this helps,
Beca

Sorry to be a pain but this one is utterly baffling! I don’t have the response is not defined area anymore, but the logic of that first if not statement does not appear to be working correctly. To be clear it should be that if condition one is not met (no he has just been pressed) and condition two is also met (they expected correct answer is not none) the message to slow should be displayed. However, if no key has been pressed and this is the correct answer response to be correct. In a lot of cases, we should see incorrect.

Bizarrely, when I tried to run my suggested code everything is “too slow”, and when I try the amended version that you suggested most recently, nothing is, “too slow.” The critical thing for my study is that correct to be displayed when the keypress matches the expected response and if you’re doing nothing is the correct response. However, if you must press a key and don’t, you get, " too slow. If you must press a key, but you press the wrong one, you get, “incorrect.”

That is why I started with a code component, because it allows the feedback to be contingent on the response. All of this was working perfectly fine as long as the allowed responses were one of two keys. And too slow only appeared if nothing was pressed. But now that nothing is one of the correct answers, no longer works.

I have tried removing all references to none in the control file as this was suggested in another post, but that doesn’t work either. I have also tried removing the quotations around the world none, in the code block.

I’m sorry if I’ve been clumsy with explaining this one, it’s just infuriating to be so close yet so far! :slight_smile: Your patience is, as always, greatly appreciated!

I think your check in the and statement is wrong still.

You started with

if not practiceresp.keys and practiceresp.corr is not "none"  :
    msg="Too Slow" 

But practiceresp.corr is whether the participant had got it right or wrong (it won’t be none).

Becca suggested

if not practiceresp.keys and practiceresp is not "none"  :
    msg="Too Slow" 

But practiceresp is the name of your keyboard (it won’t be none.

I think you want

if not practiceresp.keys and corrResp != "none"  :
    msg="Too Slow" 

Where corrResp is the name of the column in your conditions file

Alternatively you might just rethink your order. Check if correct first and then check for non- response. Then you don’t need an and at all:

If practiceresp.corr:  # stored on last run routine
    msg="Correct!" 
elif not practiceresp.keys :
    msg="Too Slow"
else:
    msg="Incorrect"

Hi @jon,

I used a similar code component but sometimes the trial feedback is correct and other times it shows a wrong feedback message. I’ll share my code here:

if not key_resp_2.keys:
thisFeedback= “Failed to respond.”
elif key_resp_2.keys == corrAns:#stored on last run routine
thisFeedback= “Correct!”
elif not key_resp_2.keys == corrAns:
thisFeedback= “Oops! That was wrong.”

My condition file is as follows:

I’m not sure if there’s something in the code that I need to change or if there’s something else?

If there’s some other information that you need me to provide, please do let me know.

If there’s something you see or can think of, I’d really appreciate your feedback.

Many thanks and best wishes,

Rubina

Hello

try

if key_resp_2.keys:
    if key_resp_2.corr:
        msg = "Correct"
    else:
        msg = "Oops! That was wrong."
else:
    msg = "Failed to respond."

Best wishes Jens

Hi @JensBoelte,

Thank you for your quick reply.

I tried the above code, but now for all the correct responses, I get “Oops! That was wrong.”

Do you have any suggestions on what I should change?

Many thanks in advance for your help.

Best,

Rubina

Hello

if you get “Oops! …” then the if-condition key_resp_2.corr does evaluate as true. What do you get when you don’t answer? That should work

Do you mind posting the code-component, the relevant part of the Excel-file and the data tab of your keyboard-component? It should look like this

grafik

Best wishes Jens

Hi

When I don’t answer, I get the “Failed to respond” message.

Here’s the code component:

if key_resp_2.keys:
if key_resp_2.corr:
thisFeedback = “Correct!”
else:
thisFeedback = “Oops! That was wrong.”
else:
thisFeedback = “Failed to respond.”

thisExp.addData(‘correct_answers’, thisFeedback)

Here’s the relevant part of the Excel-file:

Here’s the data tab of my keyboard component:

Best,

Rubina

Hello Rubina

please surround the code with triple ’ then it is properly formatted. Well, there is the correct_answer in your result file, right?

  1. How and when do you set thisFeedback?
  2. The feedback-routine follows your response-routine?
  3. The code-component is the first component in the feedback-routine?

Best wishes Jens

Hi Jens

I tried putting triple ’ (instead of " ") but sometimes the feedback is correct and sometimes it is not. Yes the correct_answer is in my result file.

  1. For $thisFeedback, I put it in the Text component. This goes after the code component.

  2. The feedback-routine does follow the response-routine but the feedback is not always right.

  3. The code-component is indeed the first component in the feedback-routine.

Best wishes,

Rubina

Hello @Rubina_Chandnani

and the text-component of $thisFeedback is set to “set every repeat”?.

Sorry, surround the code with the triple ’ here in the forum, then it is properly formatted, not in your code.

Best wishes Jens

Hi Jens,

Yes, $thisFeedback is “set to every repeat”.

This is a screenshot of my code but the problem still persists.

@Rubina_Chandnani

in Python indentation is important. It is wrong in your last else-condition. I should be only four spaces not eight.

Well, do you mind uploading your experiment and your Excel-file?

Best wishes Jens

Hi Jens,

I made the correction in the last-else condition.

Here is the experiment and condition file:

Flanker_experiment2.psyexp (59.0 KB)

Condition_file_1.xlsx (15.1 KB)

Thank you so much for your input.

If you need anything else, let me know.

Best wishes,

Rubina

@Rubina_Chandnani

do you have the stimuli as well, sorry I forgot to ask.

Best wishes Jens

Hello @Rubina_Chandnani

no need to send to images!

I changed
(1) the feedback-routine name from feedback_ to feedback and
(2) changed your image to text to get it running.

It worked for me, at least as far as I can tell. I noticed that in your Exce-file the columns left_image and right_image had a ’ at the beginning which I deleted. Bu that should not affect the feedback.

Best wishes Jens

Hi Jens,

My apologies, I was not at my computer.

I did 1) but 2) returns the name of the images not the images itself. How did you do this?

Best wishes,

Rubina