psychopy.org | Reference | Downloads | Github

How do I use a Mouse response in a Conditional task.?


#1

OS(MAC OS High Sierra 10.13.5):
PsychoPy version (2 PY3):

I did a conditional task, and it is working very well. In this task, I present one stimulus at the top (A) and two at the bottom (B and C). The responses are “left” or “right” on the keyboard. If the response is correct, one “point” is added to a total_correct and a message “correct” show on the screen, and if this score is bigger than a criterion in the excel file, it ends the training routine AB. It is working so far.

My question is: is it possible to use a mouse response in a coditional task like this that have criteria to finish the “block” of trials. I tried to find some other discussion here about using the mouse and did not find something in this way I need.

I was able to enable the mouse click but in the properties of the keyboard answer there is that option “Correct answer” that I could link to a specific response in the excel file, and if I use resp. corr== True or False it worked, but I don’t know how to proceed with the mouse response to make it conditional like this one. Can anyone help me, please?


#2

In the latest version of PsychoPy, the mouse component allows you to specify a list of ‘clickable’ stimuli, and to store information about what was clicked (eg the stimulus name).

You could compare the name of the chosen stimulus to the relevant variable from your conditions file to judge whether the response was correct or not.


#3

Thank you very much for your reply Michael!

So I should use the stimulus name, I saw this component and inserted the allowed stimuli. but I was not sure if the way would be the name or the position. Thank. you for letting me know this.

Once I used some inserted codes in the builder to make the finish criteria works, generally, I used something like:

If resp.corr == True:
total_score += 1

What should be the mouse parameter that substitutes the resp.corr?

And a second question, I see what you say about comparing the name (like comparison 1) and having in my conditions file a column (correct_response) where I insert each name of the “correct” clicked stimuli. But once the mouse does not show the option (Correct answer) where I could insert the $correct_response related to my conditions file, where should I insert this information to make it work?

Thank you very much again!!!


#4

I think this will need to be handled in code: as the mouse can gather so much more information than a simple keypress, we can’t easily implement a simple “correct” feature in the graphical component. So in your case, you could insert some code like this:

if mouse.clicked_name[0] == your_conditions_file_variable:
    # need to manually store whether the judgment was correct in the data file
    thisExp.addData('correct', 'Yes') 
    total_score += 1
else:
    thisExp.addData('correct', 'No')



#5

Hi Michael, I am sorry to bother, I am trying to make it work but I am a bit confused with the first line of the code:

mouse.clicked_name[0] -> this should be the name of my mouse response, correct?

your_conditions_file_variable - this should be the name of the column where I inserted the names of the clickable stimuli in the excel file.

should it be something like this?

if mouse.clicked_mouse_resp[0] == $req_response:

I will put some images to be clearer

Thank you very much!!!


#6

Yes, you need to use your actual stimulus and variable names, so try this:

if mouse_resp.clicked_name[0] == req_response:
  • $ is not needed anywhere in this code, as anything in a code component is Python code. i.e. the $ symbol is not a valid Python expression itself, rather it is just a prefix used as a hint to Builder to treat what follows as Python rather than a literal value. That is only necessary in some Builder fields (e.g. in a text field, it isn’t clear other one wants to display some literal text or use a Python expression, so the $ makes clear what is wanted).
  • clicked_name is a property of a Builder mouse object, which stores a list of what it was used to click (and we just want the first entry (i.e. [0]) in that list. You need to use this exact name to access this property. (i.e. not clicked_mouse_resp as you suggested above).

#7

Wow! It worked perfectly!

Thanks so much!

:slight_smile: