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?
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.
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?
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')
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).
The check is always failing, so you need to see why. Insert this before your code:
print(mouse.clicked_name)
print(correctAnswer)
but note from the code above that the clicked name(s) seems o be returned in a list, so you should probably be checking for mouse.clicked_name[0] to extract a particular entry from that list rather than the bare mouse.clicked_name (because a list, even if it contains just a single value, can never be equal to a single value).
########## Running: /Users/lpxslma/Desktop/foodGame/game_2_lastrun.py ##########
pyo version 0.8.6 (uses single precision)
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
[‘A’]
C
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
[‘B’]
D
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
[‘D’]
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
[‘C’]
C
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
[‘C’]
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
[‘C’]
D
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
[‘C’]
C
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
D
[‘C’]
D
0.8961 ERROR Requested audio device ‘auto’ that is not available on this hardware. The ‘audioDevice’ preference should be one of [u’Built-in Output’]
6.2942 WARNING User requested fullscreen with size [1024 768], but screen is actually [2048, 1152]. Using actual size
2018-08-22 14:26:48.647 python[47898:5293992] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/ff/gsm0hmc939d55vcbltl0xkr80000gq/T/org.psychopy.PsychoPy2.savedState
and the csv output is still showing all ‘0’
when i try mouse.clicked_name[0], i’ll get this error
What this shows you is that usually no valid target is clicked, and so an empty list [] is returned. This can never be equal to your stored response. Also, it has no elements to index, so we can’t ask for element 0.
You need to check your mouse component and think about how you want to handle the responses. In the first instance, the issue would probably disappear if you select to end the routine only on a “valid click”. That way the list would have at least one element, and it would have to be a valid answer (A, B, C, or D). If that doesn’t suit, then we need to alter the code to be more defensive and deal with the list being empty (i.e. there being no valid response on a given trial). That may or may not be what you want.
What I would like is that there are 4 choices (A,B,C,D). Participants can choose only one of these options and they will be provided feedback. I’ve got the feedback part figured out. Ideally, I would like to also save their answers whether right or wrong as ‘1’ and ‘0’.
Ahh, I just realised that your click-checking code is running on every screen refresh. That way, it is continually receiving non-responses and probably overwriting any actual responses. That code needs to be shifted to the “end routine” tab. That way, it will only run once per trial, after a valid click has been detected.
We need to see your current version of the code. i.e. whether you are comparing your correctAnswer variable to the whole list of responses or just one. Probably also useful to see the output of the print statements again now that the code has moved.
########## Running: /Users/lpxslma/Desktop/foodGame/game_2_lastrun.py ##########
pyo version 0.8.6 (uses single precision)
[‘A’]
D
[‘B’]
C
[‘D’]
C
[‘C’]
C
[‘A’]
D
[‘B’]
C
[‘D’]
D
[‘C’]
D
0.7595 ERROR Requested audio device ‘auto’ that is not available on this hardware. The ‘audioDevice’ preference should be one of [u’Built-in Output’]
2018-08-31 12:11:12.252 python[2307:7277124] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/ff/gsm0hmc939d55vcbltl0xkr80000gq/T/org.psychopy.PsychoPy2.savedState
We’re kind of walking in circles here. Just to reiterate, the mouse component returns a list of names, as it is possible to click on more than one (see how the values in your testing output alternate between lists and isolated values). A list containing a single value is not the same thing as that value alone. The real-world analogy here is that a bus in which a person is a passenger is not the same thing as that person. We need to do a comparison of the same types of things, by explicitly extracting the item from the list to compare to your variable, as below:
I am experiencing the same issue as suelynnmah had before, receiving a bunch of “N” instead of “Y” or a mix of “N” and “Y” while using the same command.