psychopy.org | Reference | Downloads | Github

Feedback based on image selected

I am trying to provide feedback based on wether participants mouseclicked on a specific image or not.
I have a trial routine and then a feedback routine (in a loop) as shown below:
image

Each (learning) trial contains 2 images (a learning image and on top of it, a star image). Participants have to use the mouse to click on the star image. Then based on wether they mouseclicked on the star image or not I made a code component (placed on begin routine) attached below:

if mouseclick.clicked_name=="learning_star":
    msg= "You found the star"
elif mouseclick.clicked_name=="learning_images":
    msg="You didn't find the star"
else:
    msg="You didn't find the star"

The problem I have is that I always get “You didnt find the star”, despite that I click on the star and that thr output file on the clicked_name column has the value of learning_star. Both images are clickable objects. What am I missing here?

Thanks.

Good practice is to insert some temporary debugging code, like:

print(mouseclick.clicked_name)

to check if the variable is actually containing what you think it contains. I’m going to guess in your case that it will show None or [], because if this code is in the “Begin routine” tab, it will indeed run just at the beginning of the routine, when there hasn’t been a chance to click anything yet.

You probably need to shift this code to the “End routine” tab of the routine with the mouse component, or the “begin routine” tab of the routine where the feedback will be shown…

Hi @Michael,

Thanks for your prompt reply. Actually, I had the code component at the begin routine tab of the routine where the feedback was displayed. The idea with the print function was good because I realized that when I click on the learning image it prints “learning_image” but when I click on the star it prints a list of "learning_star,“learning_image”,because there is some kind of overlap, since the one image is on top of the other. I fixed my code and it works fine now, but I guess this is a temporary solution:

if mouseclick.clicked_name==["learning_star", "learning_images"]:
    msg= "You found the star"
elif mouseclick.clicked_name=="learning_images":
    msg="You didn't find the star"
else:
    msg="Time is up..."

Is there a way to avoid that? The output file containts just one value (either learning_image or learning_star depending on the click) but the print function prints both names when I click on the star.
Any ideas?

Just saw this (Learning task correct responses ) and understood the logic, @Michael . Thanks a lot.

You could also do:

if 'learning_star' in mouseclick.clicked_name:
    msg = 'You found the star'
else:
    msg = 'You didn't find the star'

It makes sense that you get a list of two images if they overlap. I don’t understand how only one would be recorded in the data, though.