psychopy.org | Reference | Downloads | Github

Stop routine after a certain number of mouse clicks

Hello!
I am trying to design a task where a routine would end after x mouse clicks in an image.
The number of mouse clicks would be different in each condition (excel file).

My only problem is setting the number of clicks in the code component and making it work.

Thanks a lot for your help!

Océane.

OK so I am almost there, here is something in my code component:

if mouse.isPressedIn (blk1) and len(mouse.clicked_name) >= len(sequence1):
    continueRoutine = False
elif mouse.isPressedIn (blk2) and len(mouse.clicked_name) >= len(sequence2):
    continueRoutine = False

blk1 and blk2 are my objects to be clicked
sequence1 and sequence2 are numbers of times the objects have to be clicked to end the routine (in an attached excel file)
It works. Kind of.
The problem is: if sequence1= 5 clicks and sequence2=2 clicks, if I click once on blk2, I just need to click 4 times on blk1. The number of clicks are added.
The problem must be in ‘’’ len(mouse.clicked_name) ‘’’ but I am unable to solve it. Thanks again for your help.

Oceane.

mouse.clicked_name is a Python list of names like ['blk1', 'blk1', 'blk2'] if they pressed those buttons in that order. Python lists have a method called count().

So I think you can just do:

if mouse.clicked_name.count('blk1') >= len(sequence1):
    continueRoutine = False
elif mouse.clicked_name.count('blk2') >= len(sequence2):
    continueRoutine = False

THANK YOU SO MUCH!
It works perfectly.
And thank you for the explanation as well.