psychopy.org | Reference | Downloads | Github

Marking mouse click with number of clicks made

Hi,

I am building an experiment in which participants are shown a string of letters, and are later shown 12 letters and are asked to click on boxes to recall the string in the correct order. Here is a picture of that screen, which I built entirely in Builder view:

I am currently trying to make it so that when participants click on a box beside a letter, the position of the letter selected will pop up in the box. For example, if a subject means to select F as the first letter in the sequence, I want a 1 to appear in the box next to F (and so on for 2nd and 3rd positions).

I don’t want the routine to end until the participant clicks the Exit button in the bottom right corner. The Clear and Blank buttons are other options the participant can select to make their response, but are complicated in their own right and would be better saved for a different post. For now I am only focusing on the array of letters.

I was looking at other posts and came across this one: https://discourse.psychopy.org/t/give-visual-feedback-based-on-response-without-ending-trial/4736 I think that I need to add some kind of counter in order to track the number of clicks made and set that as my text similar to this example, but I only want the counted clicks to include clicks made on the boxes next to the letters.

I realize that this is a somewhat complicated design and likely won’t be solved in a single thread, but any advice on how I can tackle this problem would be greatly appreciated! Thanks!

@Kate_Checknita, an easy way to do this is to use a mouse component and a code component. Make sure mouse is not set to end routine on clicks, and in your code component:

# Begin Routine
clicked = []

# Each Frame
if mouse.isPressedIn(box1) and box1 not in clicked:
    clicked.append(box1)
    box1Text.text = len(clicked)

In this example, box1 is the shape, and box1Text is the text component inside the shape that presents the position index. It should work by counting the number of clicked objects saved in the clicked list, which should indicate current position. You will need to finish the code for box 2, box 3 etc. Also, this method will only allow you to add one number to each box, so “F” cannot take multiple positions.

1 Like

That is so helpful, thank you so much!!

Is there any way for participants to select the letter more than once? I realize the second half of the if statement is designed to get around the counter adding up when the mouse is held down for a long time, but I am hoping that on separate occasions the participant might be able to re-select a letter at test. This isn’t completely necessary and is something I can work around in my experiment, just wanted to see if you have any insight :slight_smile:

@Kate_Checknita, yes, you can do this if we change the code. This works by storing boxes in a list if they are clicked, and on each click, we check the list index of each box entry, and use that to determine the letter position:

# Begin Experiment
def clickCount(clicked, box):
    """Return the list indices of a box"""
    return [i+1 for i, x in enumerate(clicked) if x == box]
   
# Begin Routine
clicked = []
mouseDown = False  # Flag to check if mouse clicked

# Each Frame
if mouse.isPressedIn(box1) and not mouseDown:
    mouseDown = True
    clicked.append(box1)
    box1Text.text = str(clickCount(clicked, box1)).strip('[]')
# Do this for all boxes e.g.,
elif mouse.isPressedIn(box2) and not mouseDown:   
    mouseDown = True
    clicked.append(box2)
    box2Text.text = str(clickCount(clicked, box2)).strip('[]')
# Check if mouse button is released and reset flag if True
elif mouseDown and mouse.getPressed()[0] == 0:
    mouseDown = False
1 Like

Thank you again! The only problem with this is that the count for mouse clicks starts at 0, and there are brackets around the numbers (preferably they would be shown without). I really appreciate your help with this!

No problem, I have updated the code above which should give you what you need.

Amazing!!