If this template helps then use it. If not then just delete and start from scratch.
OS (e.g. Win10): Ubuntu 20.04 PsychoPy version (e.g. 1.84.x): PsychoPy 2022.2.4 Standard Standalone? (y/n) If not then what?: What are you trying to achieve?:
have an experiment where possible response to provide are:
1) correct
2) not correct
3) no response
and encode them as a specific triggers
What did you try to make it work?:
I have used the following code to encode specific responses:
if responded == 1:
if(trial_resp.keys == str(corrAns)) or (trial_resp.keys == corrAns):
trial_resp.corr = 1
elif (trial_resp.keys != str(corrAns)) or (trial_resp.keys != corrAns):
trial_resp.corr = 0
did you define the correct answer somewhere? I guess so because you use corrAns in our if-construction. In this case you could simplify your if-construction. trial_resp.corr contains 1 or 0 for correct or incorrect answers. It evaluates to true or false in an if-construction depending on your corrAns.
if trials_resp.corr:
....
You can also check key_resp.keys. If your participants did not answer, key_resp.keys evaluates in an if-construction to false. So combing everything it boils down to
if key_resp.keys:
if key_resp.corr:
msg = "correct"
else:
msg = "wrong"
else:
msg = "no answer"
You could add your triggers and code to the appropriate branch of the if-construction.
In the example I used the “standard” name PsychoPy comes up with when using the keyboard-component. You need to adapt that to your component-names.
I was going to ask a similar question. Your issue might be with the value of responded.
You can check with print(‘responded’,responded)
Also, you are using elif with no else conditions. If responded is supposed to be 1 or 0 then you can use else: instead of elif responded == 0: (which would mean that your code would work if responded was, for example, switching between 1 and undefined)
@wakecarter Thanbk you. I guess I’’ try a the way that you suggested too. I was also wondering whether by specifying better the difference from correct responses conditions (!= corrAns) - possibly by adding an and statement such as and trial_resp.keys == None in one of the statements of the if-loop, this might make work everything.