OS (e.g. Win10): Win8 PsychoPy version (e.g. 1.84.x): 1.83.04 Standard Standalone? (y/n) If not then what?: Yes
What are you trying to achieve?:
I am trying to put two pictures ( one on the left and one on the right) and when I want to select either of them, I would put the mouse pointer on one image ( the one I would select) and then click on it instead of using the keyboard (eg., left/right keys) .
I have got an idea that I use the Rating Scale with two choices (hover) and I put each choice under each picture where I can put the mouse pointer on the choice under the image. However, the problem here is that I couldnât put long space between choices.
So I would be thankful if someone could help me with this.
You need to tell us what you want the selecting to do. i.e. does this provide the answer to a question, does it end the trial, does it make one of the images appear highlighted, etc.
But in essence, no you donât want to use a rating scale. Instead, you would insert a mouse component and also a code component. In the Each Frame tab of the code component, you would have something like this:
if mouse.isPressedIn(name_of_your_left_stimulus):
# do something
elif mouse.isPressedIn(name_of_your_right_stimulus):
# do something else
Yes, I want the selecting to end the trial.And I want the output data file shows if a participant has selected the left or right image.
The name of my left stimulus is $pictureleft. In this case, Shall I insert the dollar in brackets? E.g., if mouse.isPressedIn ( $pictureleft): âŚ
I have got a list of images in the reference file.
Also, could you please provide me with the full code because I am not familiar with coding?
When adding code in a code component, never use a $. (The $ is not standard python. Its needed to signal the Builder that a string should be interpreted as python code. Code components are always python code, but other builder entry fields are ambiguous, and so a special character is needed.)
if mouse.isPressedIn(pictureleft):
continueRoutine = False
# save data if you like:
thisExp.addData('clicked', 'left')
elif mouse.isPressedIn(pictureright):
continueRoutine = False
# save data if you like:
thisExp.addData('clicked', 'right')
I used the one you put, but an error message has appeared. The message has been attached.
When I remove the coding, the experiment works.
Could you please have a look at the message if you could see what the problem is?
Thatâs probably because pictureLeft is a (unicode) string with the image file? You want to refer to the image object:
if mouse.isPressedIn(image_3):
Just to iterate on @jeremygrayâs answer: If you only care about whether the subject responded left or right, donât refer to the content of the image stimulus at all; simply refer to the image stimulus object itself:
if mouse_4.isPressedIn(image_3):
continueRoutine = False
# save data if you like:
thisExp.addData('clicked', pictureLeft)
elif mouse_4.isPressedIn(image_4):
continueRoutine = False
# save data if you like:
thisExp.addData('clicked', pictureRight)
I changed the logging so that it saves the image name.
It works, but when I click on either of the two pictures in the first trial, the experiment finishes; that is, the next trial ( the next two pictures) does not come.
One guess is that it actually loops through all the trials for the duration of your button press. In that case, your data file should have a row for each of the trials while, if it really did quit early, it should just have a row for the first trial or none at all. Let me know if you donât have the three rows.
Assuming that you have, fix the problem by either of these:
Insert a âbreakâ routine after your main routine, e.g. with a 0.3 second blank screen.
Wait for mouse release by adding this to your new âwait-routineâ in a code component instead of a time-based wait:
while np.any(mouse_4.getPressed()):
pass
⌠or you could add this code under the if-statements in my code example above.
Thank you so much We are very close to the compete solution.
I put the new code under the previous one and it successfully worked. However,
The output data file doesnât show if a participantâs response is correct or not. For example, when he chooses the correct picture, this should be marked as â1â or âcorrectâ and vice versa.
You would have a column in your conditions file specifying something that identifies the correct image. Letâs say that you call that column corrAns and that it specifies the correct image by filename:
if mouse_4.isPressedIn(image_3):
continueRoutine = False
# save data if you like:
thisExp.addData('clicked', pictureLeft)
thisExp.addData('score', int(corrAns == pictureLeft))
elif mouse_4.isPressedIn(image_4):
continueRoutine = False
# save data if you like:
thisExp.addData('clicked', pictureRight)
thisExp.addData('score', int(corrAns == pictureRight))
The == tests for equality and returns True or False. int converts these into 1 and 0 respectively.
You could also use the side of the correct image as an identifyer, e.g. having the corrAns column say âleft, right, right, leftâ etc. Then you would write that string in the test for equality:
if mouse_4.isPressedIn(image_3):
continueRoutine = False
# save data if you like:
thisExp.addData('clicked', pictureLeft)
thisExp.addData('score', int(corrAns == 'left'))
The topic looks very interesting. But what seems to me is that the mouse pointer will respond ( taking the participant to the next trial) wherever it is clicked on the screen, I donât know if you can make the mouse responds ( going to the next trial) only when either of the two pictures is clicked.
Also, it would be perfect if you could make an image appear highlighted ( or make the cursor hand on mouse over) when the mouse is put on the image before clicking on it.
@Yuu, it will only continue if you have âforce end of routineâ ticked in your mouse component. Otherwise not since continueRoutine = False only runs when the click is on an image in the above code. To make the image appear highlighted, you could either change itâs properties when a click is detected:
hi, I have a quite similar question, so I decided to include it here instead of opening a new discussion.
In my case, instead of pictures, I have polygon components (they are 16 placed as a 4x4 grid, but to make it simple, lets consider there are only two, q1 on the left side, and q2 on the right side). In my conditions file I have a column (corrAns) specifying the target polygon (the one that will be considered correct in each trial.
I tryed to follow the previous answers, but I dont get any information about mouse response positions in my output file
As with the answer to the previous question you need to make sure that your variables for which you test isPressedIn() (corrAns and q2_3 in your case) are in fact stimuli like image stimuli. corrAns is a variable that is usually defined in a conditions file not a Component of your experiment.
My question is if it possible to refer to polygons in the isPressedIn(). But as I dont get anything in my output csv file (no sign of the âclickedâ and score" columns), I am afraid there are other things I am not doing correctly.
Dear all
This has been a very useful chain of conversation and very relevant to me. I think my question will fit here. conditions.xlsx (10.4 KB)
I am starting to design one of my very simple experiment using psychopy builder view (I have used this before, so even though I am not good in programming I can understand simple codes and implement them by âadd custom codeâ).
Here is what I need:
I have six pictures appearing on screen until one of them is touched. I understand if I design it using mouse click (right by default), I can manage to make it work in touch screen.
I have added a âConditionsâ file in my loop. The âcondition.xlsxâ file has seven columns, i.e., on every trial the picture from the first row is displayed until a picture is selected as a response. The eighth column of the âcondition.xlsxâ is the corrAns stating which picture is the correct response for that particular trial.
I have set up âMouseâ as a response mode and now it correctly runs through each row and displays the trials properly.
My questionâŚ
How do I write my âcodeâ such that if the âcorrAnsâ is touched it gives a score of â1â else it gives the score of â0â. I want the data sheet to record the responses as â1â or â0â. Note, the trial ends irrespective of accuracy of the response and no feedback is required. And also can the program print the âtotal response correctâ after the completion of the task. Lets say the task has 30 trials.
Ricardo,
The issue Jon mentioned is still an issue for the addData() commands, int(corrAns == q1_3).
The value of corrAns will come from your conditions file, and its type will be string or int probably. The value of q1_3 is an image or other container, which is definitely not of type string or int. So the conditional expression will always be False, because of this type mismatch.
Think through what will work for you. One possibility might be to have the corrAns column contain strings of the form âq1_3â. Then your conditional expression could be (for the q1_3 part): int(corrAns == "q1_3") â note the quotes here.