Response feedback based on two variables

OS: Windows 10, 64-bit
PsychoPy version: v2023.2.3 (Standard Standalone)

What are you trying to achieve?:
Hi there,

I’m working on a short-term memory task and I’m inserting a code component to provide response feedback based on the condition of two variables.

The first variable “is_match” is predetermined on the excel sheet (either “TRUE” or “FALSE” as values), but for the second variable I’m calling in psychopy’s default recorded variable “pressed_key_Trial.keys”, since the feedback will depend on whether participants pressed the spacebar key or not (“space” or “None” as values—“None” being how “no response” is recorded). So the response is of the type GO/No-GO so to speak.

Whitin the trial loop there’re three routines: trial component, response feedback, and intertrial screen.
In the response feedback routine, inside the “Begin Routine” tap, I’ve inserted the following code:

if(is_match == “TRUE”):
… if(pressed_key_Trial.keys == “None”):
… … feedback_text = “Correct omission”
… … responseType = “correctOmis_trueNeg”
… elif(pressed_key_Trial.keys == “space”):
… … feedback_text = “False alarm! \n false positive”
… … responseType = ‘falseAlarm_falsePos’

… if(pressed_key_Trial.keys == “space”):
… … feedback_text = “Well done! \n it’s a hit”
… … responseType = ‘hit_truePos’
… elif(pressed_key_Trial.keys == “None”):
… … feedback_text = “Incorrect omission! \n it’s a miss”
… … responseType = ‘miss_falseNeg’

thisExp.addData(‘responseType’, responseType)

and within the “Begin Experiment” tap I initialised the respective variables (as I kept getting the warning of them being called before assignmen)t:
responseType = “ ”
feedback_text = “ ”

What specifically went wrong when you tried that?:
The problem that I have is that no matter the response emitted (and not emitted), the only feedback that is shown/registered is the “Well done! it’s a hit”, seemingly irrespective of any variables’ values. I’ve tried inserting the code component at different taps stages and routine such as at the end of the “trial routine” but to no avail.

I’m new to the experiment-builder functionality of psychopy so it is hopefully a simple mistake on where/when to make the code active, but at this point I frankly have no idea; I’ve even wondered if there’s an issue with trying to use the “None” no response value (???). Any help would be much appreciated.

Can they only press space or nothing? I think your issue is that is_match may never be “TRUE”. The value in the spreadsheet might be getting evaluated as True (no quotes).

You have a similar issue with “None” which shouldn’t have quotes. However, I could just go with if… == “space”: do stuff else: do other stuff.

Hi and thanks for taking a look. The response is recoded as space, if participants indeed press this key, or None if no key was pressed. I see what you mean about the None perhaps not having to be between quotes, I might try this… but the “pressed_key_Trial.keys” is the only dynamic variable as it depends on users’ input. The is_match is predetermined as it’s information being fed into the trial, so as long as it is read, it should be evaluated as stated in the spreadsheet.

About the code do you mean changing it to the form of(?):

if is_match == “FALSE” and pressed_key_Trial.keys == “space”:
…responseType = “Hit”
elif is_match == “FALSE” and pressed_key_Trial.keys == None:
…responseType = “incorrect omission”
elif is_match == “TRUE” and pressed_key_Trial.keys == “space”:
…responseType = “false alarm”
elif is_match == “TRUE” and pressed_key_Trial.keys == None:
…responseType = “correct omission”

Yup! You’re right. The problem was the fact that psychoPy seems to read the TRUE value of my spreadsheet as phyton’s True logical.

It never occurred to me that this may be the case, since programming languages can be so picky about key words. Thank you so much!