Hello! I’m using PsychoPy 2021.2.3. My lab is trying to do a simple flanker task and are currently trying to figure out how we can provide feedback based on the responses provided in the two blocks. We have minimal coding experience and so have been trying to use the GUI with no luck.
We’ve seen the following on the psycho py site but was wondering how we could edit it to fit our task
In this case the feedback routine would need to come after the loop (the block of trials) and the message needs to use the stored data from the loop rather than the key_resp directly. Accessing the data from a loop is not well documented but totally possible.
In this case, to get all the keys pressed in a numpy array:
trials.data[‘key_resp.keys’] #numpy array with size=[ntrials,ntypes]
If you used the ‘Store Correct’ feature of the Keyboard Component (and told psychopy what the correct answer was) you will also have a variable:
#numpy array storing whether each response was correct (1) or not (0) trials.data[‘resp.corr’]
So, to create your msg, insert the following into the ‘start experiment` section of the Code Component:
msg=‘doh!’#if this comes up we forgot to update the msg!
and then insert the following into the Begin Routine section (this will get run every repeat of the routine):
nCorr = trials.data[‘key_resp.corr’].sum() #.std(), .mean() also available meanRt = trials.data[‘key_resp.rt’].mean() msg = “You got %i trials correct (rt=%.2f)” %(nCorr,meanRt)
Thank you!