Help us to help you: we don’t know it isn’t causing the issue unless we can see the indentation.
The issue is actually worse than that: currently you aren’t measuring even the first reaction time correctly, but rather, the last time at which the mouse was pressed, instead of when it was first pressed. i.e. on each screen refresh, you will be checking if the mouse is pressed in your stimulus, and if so, overwriting the previously measured reaction time with the current time, until the button is no longer held down. So you need to add a few more flags to keep track of where you are at:
Begin routine tab:
background_already_clicked = False
star_already_clicked = False
clicks = 0
timer1.reset()
Each frame tab:
if not background_already_clicked and mouse.isPressedIn(background):
thisExp.addData('rt', timer1.getTime())
background_already_clicked = True
clicks = clicks + 1
elif not star_already_clicked and mouse.isPressedIn(star):
thisExp.addData('rt2', timer1.getTime())
star_already_clicked = True
clicks = clicks + 1
if clicks == 2:
continueRoutine = False
Now if that code doesn’t work, the trick is to insert temporary debugging code within various parts of your code, like:
print('Background clicked')
Sprinkle print statements like that around until you can figure out why the second check isn’t triggering.
Also be thinking carefully about when code should run. It is correct to create the timer at the start of the experiment, but it should be reset at the start of each routine. It isn’t correct to create the clicks
variable at the start of the experiment, as it needs to be set to zero at the start of each routine anyway, so setting it to zero at the start of the experiment is redundant.
Lastly, if I had to guess, my suspicion as to why your second check is not triggering is that there is a conflict between your code and the Builder mouse component. Because you are handling this functionality in code, don’t set the mouse component to force the end of the trial, or to record reaction times or to specify the valid clickable stimuli.