Longer Mouse Clicks Affect Data

Hi All,

I am using the builder mode to create a program where a mouse click inside a stimulus causes a reward to occur. The variables that I am interested in measuring are the time of each click, its location, and whether or not it was within the TargetStimulus. To that end, I have created the following bit of code below.

Unfortunately, while my experiment works fully, my data file looks messy because my variables of interest are recorded for each frame that the click is made. That is, longer clicks will result in many data points when all I want is the time, location, and yes/no for in stimulus click at the time the click is started. I’m sure this is an easy fix but I have been working on this problem for hours with no improvement.

if mouse1.isPressedIn(Cue1) and not (mouse1.isPressedIn(TargetStimulus)):
        thisExp.addData('mouse1Time',t)
        thisExp.addData('mouse1position', mouse1.getPos())
        thisExp.addData('Instimulus', 0)
        thisExp.nextEntry()
elif (mouse1.isPressedIn(TargetStimulus)):
        thisExp.addData('mouse1Time', t)
        thisExp.addData('mouse1position', mouse1.getPos())
        thisExp.addData('Instimulus', 1)
        thisExp.nextEntry()

You just need to maintain a flag that says whether or not the data has been stored on this trial.

e.g. in the Begin routine tab, put something like this:

dataStored = False

and then in your every frame code, check and change that flag:

if not dataStored:
    thisExp.addData('mouse1Time',t)
    thisExp.addData('mouse1position', mouse1.getPos())
    thisExp.addData('Instimulus', 0)
    dataStored = True

Don’t use thisExp.nextEntry()

1 Like