Help with mouse clicks and timing

If this template helps then use it. If not then just delete and start from scratch.

OS: Win10 :
PsychoPy version: 3 :
Standard Standalone? Yes
What are you trying to achieve?:

I have 9 images in a 3x3 grid that I am trying to make selectable.
I would like it so that participants can select one or multiple images, turning them red when selected (and logging the selection and timestamp) and turning them back to their normal color when deselected. A next button at the bottom moves them to the next set of images.

Right now - the code works, but sometimes clicks are missed or not registered. All in all it seems like the loading time for the screen is slow, and that its either not refreshing frames fast enough - or that I’m waiting too long.

What did you try to make it work?:

Right now it loads images based on a list of images in an excel sheet that is the stim for the trial loop.

I have a code snippet in the builder that looks like the following:

Begin Routine:

for stimulus1 in [top_right,top_center, top_left, middle_right, middle_center, middle_left, bottom_left, bottom_center, bottom_right]:
    stimulus1.color = 'white'
    stimulus1.currentClick = 0

Each Frame:

for stimulus1 in [top_right,top_center, top_left, middle_right, middle_center, middle_left, bottom_left, bottom_center, bottom_right]:
        if mouse.isPressedIn(stimulus1):
            thisExp.addData('clicked', stimulus1.name)
            if stimulus1.currentClick == 0:
                stimulus1.color = 'red'
                stimulus1.currentClick = 1
            else: 
                stimulus1.color = 'white'
                stimulus1.currentClick = 0
        win.flip()

What specifically went wrong when you tried that?:

Its currently lagging and too slow meaning that clicks arent registered. Thoughts on how to make it more consistent in loading and registering clicks?

Include pasted full error message if possible. “That didn’t work” is not enough information.

Hi @M_L, there was a similar post about issues using the mouse to change the color of squares. Please see the solution here.

@dvbridges thank you! - I’ve implemented a bit of it - but I’m still struggling with the timing a tad where I click and nothing happens. Do you know if I’m missing something in regards to when the images are refreshing?

Remove the win.flip() line.

Builder scripts control their own drawing cycle, and hence calls this function automatically, once per drawing cycle. By calling this function manually (and many times per check), you’ll be disturbing Builder’s timing and performance, which might explain some of the issues you are seeing.