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"