Mouse click conditional feedback

OS (e.g. Win10): This will be used on a Windows10 laptop with a touchscreen monitor.
PsychoPy version (e.g. 1.84.x):
What are you trying to achieve?: I have an RMTS task, where the animal will have to first choose the correct match, image below. If they choose the correct match, I need an X and O to come up, so they can choose the corresponding symbol. If they click the right symbol, it will activate my reward.exe otherwise they will get a 10 second timeout with a blank screen. All of the touches will be with “mouseclicks” through the tablet. With human participants I have been able to just use the keyboard and use the Correct Answer option to insert the $CorrAns variable in my excel file, and use the code below:
respond = ‘’

if train_resp.corr:
respond = ‘Correct!’
TimeOut=0
else:
respond = ‘Incorrect.’
TimeOut=5

My plan was to have resp.corr = reward.exe but, I’m not seeing the Correct Answer option in the mouse click function in the builder.
Is there an equivalent to this with mouse clicks? So I can store correct and incorrect clicks to provide the animals with feedback?

My second question is regarding the matching portion of the task: if they select the matching color, the X and O appear, if not they get a timeout and move to the next trial. I’m not sure what would be the most efficient way to have the X and O text component appear on a correct match click? **Edit, I have added transparent polygon rectangles over my two choice stimuli. I am trying to find a way to tell the program “if the correct polygon is clicked (either Left or Right), show TextO and TextY (my symbols appear), else, move to next trial”. But am not sure how to tell it which polygon click is correct?

image

Any advice on either of these questions would be greatly appreciated!

You currently need code for scoring mouse clicks in PsychoPy.

You might find my Emotional Stroop for mobile online demo useful.

Here I’ve used the following code in Each Frame

if t < .5:
    mouserec = mouse.getPos()
else:
    mouseloc = mouse.getPos()
    if mouseloc[0]==mouserec[0] and mouseloc[1]==mouserec[1]:
        pass
    elif button1.contains(mouse):
        response=0
        butcol1='yellow'
    elif button2.contains(mouse):
        response=1
        butcol2='yellow'
    elif button3.contains(mouse):
        response=2
        butcol3='yellow'
    elif button4.contains(mouse):
        response=3
        butcol4='yellow'
    if response < 99:
        if response==thisColour:
            Score = 1
        continueRoutine=False

For touchscreens I use the contains method combined with a change in coordinates rather than waiting for a click.

This code translates the mouse response into a variable (response) and changes the colour of the pressed button for feedback.

The feedback code is in End Routine and includes code for the possibility of a parallel keyboard response.

block_results[thisBlock[2]][0]+=1
if Response.corr == 1 or Score == 1:
    block_results[thisBlock[2]][1]+=1
    rtList.append(round(t*1000)-500)
    feedbackImage='tick_white.png'
else:
    feedbackImage='cross_white.png'
    
if thisBlock[2] > 0:
    showFeedback = 0
 

I ended up finding a solution, and then realizing today it would not work with the touchscreen due to the double click issue. I searched through other questions and ended up finding your crib sheet with the “hover” solution, and I have been trying to use that to fix the double click problem. Now the issue is with the feedback.
The code below is what I’ve added to the routine with my mouse and two polygon choices:
image

Then this is the code on the next routine for providing feedback:
image

So it was dependent on the column created for mouseclicks. But now that it is not recording mouseclicks I’m trying to figure out a different way to provide correct vs incorrect feedback for the Left/Right choices.

I think you need to use the contains method.

Thank you. I have changed it to the contains method. For my feedback I will have it calling an .exe file to dispense a food reward and play a sound for a correct response, and play a different sound for incorrect responses. I guess where I am confused is how to tell the program what the correct and incorrect responses are for each trial/image, and I was unable to decipher that from reading the code, as I’m still trying to become proficient in python. With the key responses I can usually make a column in my excel file with the correct key for each image and use if respond.corr == 1. But am unsure to to get the same effect with the mouse, I have in my excel sheet “Left” or “Right” which are also the names of my polygon choices but do not know what to do with that information in the code.

**EDIT
Here is what I have come up with:


It is not printing respond like I had hoped to ensure it is working the way I think it is, but definitely getting closer.

Logically it can never reach the final elif because one of the previous clauses will already have been used.

Do you have a mouse component called mouse created in a previous routine?

I think I have solved the issues and it all seems to be working (at least on my laptop I’ll have to test the touchscreen later). Here is what I have:


image