Signalling response after mouse click

Hi,

I have five images appearing on the screen and I want to signal to the participant which one they have clicked.
The participant will select one image via mouse click and I want the one they choose (regardless of whether or not it is the correct choice) to have a border surrounding it

I have polygons behind each of the images that participants can click.

I want the colour of the polygon to change from grey to (some other colour) whenever a participant clicks on an image. I also want the colour to change back to grey after participants press the image because participants can click on multiple images in a trial. So I want the border to change to a different colour for every mouse click that participants make on an image.

My current code is:
if mouse.isPressedIn (PRightOne): PolygonColor = 'white' in BeginRoutine

and added this as the fill color for the polygon image

I am getting an error saying that PolygonColor is not defined as well as other errors.

Let me know how I can solve this problem,
Thanks!

That error is easy to fix but we should really deal with all of them, so please provide full details.

This is the error I’m getting
image

But you also said:

Is this in fact the only error to deal with?

Yes, this is the only one coming up right now

OK. How about:

  • just set the colour of each polygon to be constant, with an initial value of grey.
  • Then we can handle the colour changing entirely in code, in the “each frame” tab of a code component (make sure the code component is above the other stimuli, so that they respond immediately to any changes, rather than waiting for the next frame).
polygons = [polygon_RightOne, polygon_PWrong1, polygon_PWrong2, polygon_PWrong3, polygon_PWrong4]
images = [PRightOne, PWrong1, PWrong2, PWrong3, PWrong4]

# check for a mouse click in each image stimulus. If detected, change
# the colour of its corresponding polygon:
for i, image in enumerate(images):
    if mouse.isPressedIn(image):
        polygons[i].color = 'white'
    else:
        polygons[i].color = 'grey'

It seems like nothing is happening when I added this code.
I am not getting any errors but nothing happens when I try to click one of the images.

Were you sure to set the colour of each polygon stimulus to be “constant” rather than to “set every frame”? If it is set to update, that will conflict with the updating being done in the code.

Otherwise, try putting in the extra line below, to see if the click is actually being detected:

# check for a mouse click in each image stimulus. If detected, change
# the colour of its corresponding polygon:
for i, image in enumerate(images):
    if mouse.isPressedIn(image):
        print('Detected click in image ' + str(i)) ## TEMPORARY debugging line
        polygons[i].color = 'white'
    else:
        polygons[i].color = 'grey'