Questions about mouse click/

in ‘each frame’, I wrote the codes like:cnt was initialized to 0 in ‘start of the routine’
print(“itsss”,cnt)
cnt+=1
for num in numbers:
if mouse_player.isPressedIn(num):
print(‘num is’,num)
cnt-=1
if_clicked = True
num.setColor(‘red’)
if turn == PLAYER:
col = i
print(‘playplayplayplayplayplayplayplayplayplayplayplay’)
but I checked the output, it’s like:
itsss 206
itsss 207
itsss 208
num is Rect(class=<class ‘psychopy.visual.rect.Rect’>, anchor=(‘center’, ‘center’), autoDraw=True, autoLog=True, closeShape=True, color=method-wrapper(…), colorSpace=‘rgb’, contrast=1, depth=-48.0, draggable=False, fillColor=array([1, 1, 1]), fillColorSpace=‘rgb’, fillRGB=array([1, 1, 1]), interpolate=True, lineColor=array([1, 1, 1]), lineColorSpace=‘rgb’, lineRGB=array([1, 1, 1]), lineWidth=1.0, name=‘poly_num_5’, opacity=1.0, ori=0.0, pos=array([ 0.05, -0.1 ]), size=array([0.05, 0.05]), units=‘height’, vertices=ndarray(…), win=Window(…))
playplayplayplayplayplayplayplayplayplayplayplay
itsss 208
num is Rect(class=<class ‘psychopy.visual.rect.Rect’>, anchor=(‘center’, ‘center’), autoDraw=True, autoLog=True, closeShape=True, color=method-wrapper(…), colorSpace=‘rgb’, contrast=1, depth=-48.0, draggable=False, fillColor=array([ 1, -1, -1]), fillColorSpace=‘rgb’, fillRGB=array([ 1, -1, -1]), interpolate=True, lineColor=array([ 1, -1, -1]), lineColorSpace=‘rgb’, lineRGB=array([ 1, -1, -1]), lineWidth=1.0, name=‘poly_num_5’, opacity=1.0, ori=0.0, pos=array([ 0.05, -0.1 ]), size=array([0.05, 0.05]), units=‘height’, vertices=ndarray(…), win=Window(…))
playplayplayplayplayplayplayplayplayplayplayplay
itsss 208
num is Rect(class=<class ‘psychopy.visual.rect.Rect’>, anchor=(‘center’, ‘center’), autoDraw=True, autoLog=True, closeShape=True, color=method-wrapper(…), colorSpace=‘rgb’, contrast=1, depth=-48.0, draggable=False, fillColor=array([ 1, -1, -1]), fillColorSpace=‘rgb’, fillRGB=array([ 1, -1, -1]), interpolate=True, lineColor=array([ 1, -1, -1]), lineColorSpace=‘rgb’, lineRGB=array([ 1, -1, -1]), lineWidth=1.0, name=‘poly_num_5’, opacity=1.0, ori=0.0, pos=array([ 0.05, -0.1 ]), size=array([0.05, 0.05]), units=‘height’, vertices=ndarray(…), win=Window(…))
playplayplayplayplayplayplayplayplayplayplayplay
itsss 208
num is Rect(class=<class ‘psychopy.visual.rect.Rect’>, anchor=(‘center’, ‘center’), autoDraw=True, autoLog=True, closeShape=True, color=method-wrapper(…), colorSpace=‘rgb’, contrast=1, depth=-48.0, draggable=False, fillColor=array([ 1, -1, -1]), fillColorSpace=‘rgb’, fillRGB=array([ 1, -1, -1]), interpolate=True, lineColor=array([ 1, -1, -1]), lineColorSpace=‘rgb’, lineRGB=array([ 1, -1, -1]), lineWidth=1.0, name=‘poly_num_5’, opacity=1.0, ori=0.0, pos=array([ 0.05, -0.1 ]), size=array([0.05, 0.05]), units=‘height’, vertices=ndarray(…), win=Window(…))
itsss 208
itsss 209
I really don’t know why there’re 5 itsss 208 and 3 playplay… with only 1 mouse click.
Please help me find out the problem… I really don’t know how to fix this problem.
Thank you very much.

The mouse click is recorded for the duration the mouse button is down, rather than just once. This can lead to flying through trials too quickly (they appear to skip). There are two approaches to prevent this.

  1. Ensure there is a delay before the mouse can be clicked, either by using an ISI/ITI or by setting the mouse start time to 0.5 seconds.

  2. Add a flag, e.g. mouseClicked = False in Begin Routine; only register the click in the Each Frame tab if mouseClicked == False and then set it to True in the code that registers the click. If you need muliple clicks in the same routine then you could set it to a value that represents that object and only register clicks where a different object has been clicked.

1 Like

Thank you so much! I exactly need multiple clicks in the same routine and I tried your method. But there was a problem that, the player can’t click on the same button in two turns. I’m thinking whether I can record the time between two mouse responses. But I’m reallly not sure what the good solution is.

Begin Routine

timeClicked = 9999999

Each Frame

for num in numbers:
     if mouse_player.isPressedIn(num) and t > timeClicked + .03:
          timeClicked = t
          if_clicked = True
          num.setColor(‘red’)
         etc