I am setting up an experiment where participants will have to select one of two stimuli (in this case, two different pictures: Rome or Paris). The thing that I would like to do is for my code to determine randomly a “correct” answer on every trial (either Paris or Rome) and then provide participants with feedback based on their keyboard answers (keys: R = Rome; P = Paris)
I’ve used the following code as a model: https://www.psychopy.org/recipes/builderFeedback.html#feedback-after-a-trial
So basically what I’ve done is that I’ve added this piece of code at the very beginning of the experiment:
msg='doh!'#if this comes up we forgot to update the msg!
And then added this at the prepare routine “Feedback” part:
if not key_resp.keys : msg="Failed to respond" elif resp.corr:#stored on last run routine msg="Correct! else: msg="Oops! That was wrong"
And created a ‘conditions.xls’ file with a column for cities (Rome and Paris) and CorrAns (R and P, respectively).
Unfortunately, and regardless of what key I press on every trial, I always get the “doh!”, which means that my code is not updating the message. Maybe because it simply doesn’t know what the correct answer is, so it cannot update it?
This is the part of the code where I define the two “correct” answers P and R:
if key_resp.status == STARTED: theseKeys = key_resp.getKeys(keyList=['p','r'], waitRelease=False) if len(theseKeys): theseKeys = theseKeys # at least one key was pressed # check for quit: if "escape" == theseKeys: endExpNow = True key_resp.keys.append(theseKeys.name) # storing all keys key_resp.rt.append(theseKeys.rt) # was this 'correct'? if (key_resp.keys == str(corrAns)) or (key_resp.keys == corrAns): key_resp.corr = 1 else: key_resp.corr = 0
Thanks in advance!