Counter for the valid clicks in the memory experiment


In the experiment,I will show 8 circles in the specific locations and ask participants to remember them (for example blue circle locates in the origin and when I ask them to show the location of it, they need to show the location with a mouse click). I will ask the locations of 8 objects for 5 times in the test phase. I want PsychoPy to count the invalid responses. If the invalid responses are 3, participants should be directed to study phase again.

What should I write in the code?Where should I add the code(begin experiment, begin routine etc.)?

You’ll need a variable to count invalid responses. I assume, that you have a conditions file, where you define the correct response (correct_pos) and that you have an outer loop which repeats the test phase and an inner loop handling the individual trials of the test. The code below won’t run out of the box. It is just meant to point you in the right direction and you’ll have to adapt it to your experiment.

Begin Experiment

circle_list = [(circle1, "blue"), (circle2, "red"), (circle3, "green")]    

Each Frame

for color, circle in circle_list:
    if mouse.isPressedIn(circle):
        click_color = color
        continueRoutine = False

End Routine

if click_color == correct_color:
    count_corrects += 1

In a routine following your inner test trials loop, you’ll have to insert a code component, which checks your condition

if count_correct >= 3:
    outer_test_loop.finished = True
    count_corrects = 0

Hello Lukas,

Thank you for your detailed answer. Since I created polygons from Builder, do you know how can I create a condition file for them?

I edited the code in my answer above to pair a color string with every circle object. Your csv conditions file could then look like this:


However, I’m not sure, if I understood your design correctly.

Thank you so much Lukas. I am trying to apply these codes into the experiment. I will write the last version of the code when it works.

1 Like