Selecting two images from four

OS (e.g. Win10): win10
PsychoPy version (e.g. ): 2020.2.6
Standard Standalone? (y/n) y

We want to place four circles on the screen from which the participant can select only two. Ideally the circles will act like radio buttons and go black when selected.

We tried this with key presses where each circle had a corresponding key but could not get this to work due to the fact that you could press each key more than once amongst other issues. See here: Recording two consecutive (correct) answers in one trial (we didn’t even get to modifying the image!)

We tried using the mouse, but again became unstuck.

Any ideas on how to achieve this? We’re struggling to express the issue in words in order to find a working solution. Bear in mind, whatever we do in Builder will need to be easily converted to Pavlovia (and JS).

Justin and Sophie.

Insert a code component. In the “begin routine” tab, put something like:

selected_indices = []

then in the “each frame” tab, something like:

for index, stimulus in enumerate([stim_0, stim_1, stim_2, stim_3]):
    if mouse.isPressedIn(stimulus) and not stimulus.fill == 'black':
        if len(selected_indices) < 2:
            stimulus.fill = 'black'
            selected_indices.append(index)

I’m assuming you’re using polygon stimuli for the circles, which should have a .fill attribute.

Just to build on this - if you want to eventually take this online you might encounter some issues with enumerate (as it is a python method). This demo on pavlovia uses a similar method to what I think you need though. https://gitlab.pavlovia.org/demos/botchecker

Participants see 6 images and click 3 of them (the ones that are cats) - I would suggest taking a copy of this (you can click the fork icon or the cloud to download) and seeing if any of the code components/structure help in making your task :slight_smile:

Let us know how you get on,
Becca

Thanks Becca / Michael - will take a look and get back with an update.

Hi Becca/ Michael,

I am working on this with Justin, thank you for your advice. I have tried using that demo code as suggested and I am now able to click on the polygons so they change colour but I cannot work out how to code it so only two clicks are allowed in total (and not more than one on each of the 4 polygons). The count doesn’t seem to be working and after the trial is finished it doesn’t move onto the next one.

My code so far -

Begin routine:

count = 0
errormessage = 100

images = [A_resp, B_resp, C_resp, D_resp]

clicked_images=[]

for im in images:
    im.clicked=False

Each frame:

# set image opacity if mouse hovers over image
# to show that it is clickable (or already clicked)
# a count variable is used because we cannot use the 
# 'enumerate' method in JS

for im in images:
    if im.clicked ==False:
        if im.contains(mouse):
            im.opacity = 0.5
        else:
            im.opacity = 1
    if mouse.isPressedIn(im): 
        if im.clicked == False: 
            im.opacity = 0.3
            clicked_images.append(im)

            im.clicked=True

            count = count + 1
            errormessage = count
        
if count > 2 :
    continueRoutine == False

I hope this makes sense! I want to make it so the participants are only allowed to click once on two of the ‘resp’ polygons which then turn grey and then they are moved on to the next screen.

Sophie

Please explain exactly what you mean by this.

In that case, the trial hasn’t finished.

I’m not familiar with that attribute. Is this a custom addition?

Hi Michael, I can confirm that is a custom attribute that I added :slight_smile:

Becca