# Before the blocks start:
# initialize a total-holding variable and trial and block counters
totcorrect=0
ntrials=0
blocknum=0
# initialize a message
totmsg=''
for each block:
# at the start of the block, print the feedback message
if totmsg > '': # don't paint an empty message, if no blocks are completed
# display the total message
print totmsg
# or more likely, draw it onto the Window
# set the text of a textStim to totmsg
# then draw the textStim and flip the window.
# now for each trial:
# do the trial and collect the subject's answer
# .... get subjectanswer....
# now still inside the block, at the end of each trial:
if subjectanswer==correctanswer: totcorrect+=1 # add 1 to counter
of correct answers
ntrials +=1 # add 1 to counter of how many trials
# now inside the block but after all trials are done,
# and before the next block starts, set the message to display the
totals and percent:
blocknum += 1 # increment the block counter of how many blocks are done
totmsg="In block %d just completed you got %d correct out of %d, which
is a score of %3.2f percent"%(blocknum,
totcorrect,ntrials,(float(totcorrect)/float(ntrials))*100.0 )
# zero out the counters for the next block
totcorrect=0
ntrials=0
# and now continue to the start of the next block where this new
totmsg will be displayed
I guess you have to figure out how to insert the counter initialization
and increment commands into the GUI-generated code, or turn them into
little functions that you can call in the GUI
I hope this helps.
-Dave
In your case, however, the feedback routine would need to come after the
loop (the block of trials) and the message needs to use the stored data
in that loop. Accessing the data from a loop is not well documented but
totally possible.
if you had a loop called 'trials', and within it a keybooard component
called 'resp' then you will have a python variable in your experiment
called::
trials.data['resp.keys'] #numpy array storing all the keys pressed
in different trials
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::
trials.data['resp.corr'] #numpy array storing all the keys pressed
in different trials
You can take the sum of correct answers with::
nCorr = trials.data['resp.corr'].sum() #numpy arrays also have
methods like std(), mean()
msg = "You got %i trials correct" %(nCorr) #formatted strings in
python (see link below)
So you need to use code like the two lines above in a Code Component,
and then set a Text Component to have text=$msg (and remember that this
should be set to change every repeat!)
The attached experiment gives an example. It won't actually run because
it doesn't have a trial list file, but you can copy the code 'feedback'
Routine from the experiment (see the experiment menu) and paste it into
your own experiment. Obviously you'll need to adapt the Code Component
in that routine to fit the names of your loop and Keyboard Component. I
hope at some stage to add template routines for things like feedback
into Builder.
enjoy,
Jon
--
Dr. Jonathan Peirce
Nottingham Visual Neuroscience
This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.
This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.