Selection of multiple images per trial with the mouse

64-bit OS (Win10)
PsychoPy version 2021.1.2
Standalone standard? Yea

Doubt:
In my experiment, in each trial, I present 4 images simultaneously and I want my participants to select with the mouse how many images they prefer among the 4. So, I could have a participant who selected 1 images, 2 images, 3 images, 4 images or no image. In case he does not want to select any image, there is an image of a button called “Next”.

The problem is that I wanted the trial to end only when the participant clicked next, but that all the clicks on the images he selected were computed and left on the data output.

In addition, I would like there to be a way of clicking on each image, the image would be detached, with some kind of mask or border that would show the participant that that image was selected when clicking.

I am very amateur in creating codes and I need help in that regard.

So, I would be very grateful if someone could help me with this.

Sincerely,
Edimilson

Insert a code component (from the “custom” component panel) and put something like this in its “each frame” tab:

if mouse.isPressedIn(your_next_stimulus_name):
    continueRoutine = False

Also replace mouse with the actual name of your mouse component, if necessary.

In that mouse component:

  • de-select “Force end of routine”, as you are handling that in code now.
  • in the list of “clickable” stimuli, put the names of the relevant stimulus components, separated by commas.

Start by googling something like “psychopy highlight clicked stimulus” and come back to us with further questions if necessary.

Hi There,

There is also a demo of this available here that does something similar bot-checkers [PsychoPy]

files here demos / botChecker · GitLab

Hope this helps,
Becca

It worked, I managed to do it!

Thank you very much, your response was very helpful!

This helped me a lot to understand the structure of the code to highlight the selected images! I was able to successfully adapt to my experiment.

Thank you very much Becca!

Hi Becca, sorry to be resuming the discussion.

The experiment ran well in Psychopy’s Bilder, but I had a problem when uploading my experiment to Pavlovia. The following message occurred: TypeError: clicked_images.append is not a function

This function is described in a code component as follows:

Each Frame:

for im in images:
     if im.clicked == False:
         if im.contains (Mouse_1):
             im.opacity = 0.5
         else:
             im.opacity = 1
     if Mouse_1.isPressedIn (im):
         if im.clicked == False: #if it has not yet been clicked
             im.opacity = 0.5
             clicked_images.append (im.image)
             print (clicked_images)
             im.clicked = True

How could I solve this error to run on pavlovia?

Switch the “Code type” from “auto → JS” to “Both”, so that you can manually edit the generated JavaScript. In that JavaScript, try replacing append with push, which I think is the JavaScript equivalent.

1 Like

Absolutely, or add a code component to the start of your experiment, set code type to “JS” and add

Array.prototype.append = [].push;

(but note this might cause trouble if you are using editable textbox)

2 Likes

Thank you very much!

This document helped a lot! I managed to solve from it!