I'm using psychopy to build a cognitive task. I have 5 circles on the screen and the participant needs to pressed on the good circle. My code :
if mouse.isPressedIn(cercle_1):
continueRoutine = False
# save data if you like:
thisExp.addData('correct', 1)
thisExp.addData('RT', t)
elif mouse.isPressedIn(cercle_2):
# save data if you like:
thisExp.addData('correct', 0)
thisExp.addData('RT', t)
continueRoutine = True
elif mouse.isPressedIn(cercle_3):
# save data if you like:
thisExp.addData('correct', 0)
thisExp.addData('RT', t)
continueRoutine = True
elif mouse.isPressedIn(cercle_4):
# save data if you like:
thisExp.addData('correct', 0)
thisExp.addData('RT', t)
continueRoutine = True
elif mouse.isPressedIn(cercle_5):
# save data if you like:
thisExp.addData('correct', 0)
thisExp.addData('RT', t)
continueRoutine = True
The problem is that my datafile only contains the response time (RT) and the info of the circle_1. I would have no idea if the participant tried other circle before pressing on circle_1.
Question : How can I have in my csv file infos about all the times a participant pressed the mouse bouton.Maybe before pressing cercle_1, he pressed the cercle_3. Right now, I only have how long it took to get the correct answer.
It sounds like you want to record a sequence of events in the trial. This can be hard to find an appropriate data structure for, but in your case, I can think of two solutions.
Have a column (e.g. n_wrong
) and count the number of non-circle_1 responses. In Begin routine add
n_wrong = 0
Then in each frame add:
if mouse.isPressedIn(cercle_1):
thisExp.addData('correct', 1)
thisExp.addData('RT', t)
continueRoutine = False
elif mouse.isPressedIn(cercle_2) or mouse.isPressedIn(cercle_3) or mouse.isPressedIn(cercle_4) or mouse.isPressedIn(cercle_5):
thisExp.addData('correct', 0)
thisExp.addData('RT', t)
n_wrong += 1 # One more error recorded!
# Now wait until the mouse release to prevent recording 60 wrong clicks per second!
while any(mouse.getPressed()):
pass
Then under end routine add:
thisExp.addData('n_wrong', n_wrong)
The other is to have a column for each circle and shift those from "unpressed" to "pressed" when they are clicked. Then the column cercle1
would correspond to what you currently call the correct
column. So under begin routine:
# Mark all non-target cirlces as unpressed
thisExp.addData('cercle1', 0)
thisExp.addData('cercle2', 0)
thisExp.addData('cercle3', 0)
thisExp.addData('cercle4', 0)
thisExp.addData('cercle5', 0)
Then under each frame I would do this:
if mouse.isPressedIn(cercle_1):
thisExp.addData('cercle1', 1)
continueRoutine = False
if mouse.isPressedIn(cercle_2):
thisExp.addData('cercle2', 1)
if mouse.isPressedIn(cercle_3):
thisExp.addData('cercle3', 1)
if mouse.isPressedIn(cercle_4):
thisExp.addData('cercle4', 1)
if mouse.isPressedIn(cercle_5):
thisExp.addData('cercle5', 1)
The latter approach could be extended with reaction times by adding columns called cercle1_rt
etc. but then you'd also need to do the while any(mouse.getPressed()): pass
trick to record the onset and not just the release.