Hi! I’m new to PsychoPy. I want to make a color changer: anytime the participant clicks on colored boxes, an empty polygon color changes to the color clicked. I’d like to output the name of the color clicked and the time of the clicks.
So far I can’t change the polygon color more than 2 times on every trial, regardless how much I click on the colored boxes.
The boxes’ colors came from a conditions file and are randomized as the trial loops.
clickables = [box1, box2, box3]
for clickable in clickables:
if mouse.isPressedIn(clickable):
clickedlist = clicked_things.append(clickable.name)
thisExp.addData('box', clickedlist)
thisClickTime = clickClock.getTime()
clicks = thisClickTime
thisExp.addData('RT', clicks)
for clickable in clickables:
if clickable.name in clicked_things:
polygon.color = clickable.fillColor
I am not sure that this does what you want it to do:
That’s because clicked_things will contain multiple values after multiple clicks and therefore will change polygon.color rapidly multiple times each frame and always end on the color of box3 (last element in clickables). So, what you need is
for clickable in clickables:
if clickable.name == clicked_things[-1]:
polygon.color = clickable.fillColor
This should set polygon.color to the color of the most recently clicked box.
Also another caveat: If your participants hold the mouse button down for more than a frame (which they probably will), you will end up with a lot of redundant and confusing data. What I usually do to prevent this is checking whether the mouse was NOT pressed in the last frame and only then run the code that should be run when the mouse is pressed.
Thank you a lot, there were things I wasn’t considering… I got this error:
if clickable.name == clicked_things[-1]:
IndexError: list index out of range
################# Experiment ended with exit code 1 [pid:9680] #################
What I’m tryig to do:
1 - The participant see 4 boxes on the screen, 3 are colored and clickable (box1, box2, box3). As the participant clicks the colored boxes, the fourth box (polygon, not clickable) will change its color to match the color clicked.
It is a kind of conrifmation - click on red box, the empty polygon will turn red and so forth.
2 - The trial have a fixed duration (15 seconds). During that time, the participant may click as much as he/she wants and everytime the 3 boxes are clicked, the fourth box change its color accordingly.
3 - I need to output to the XLS file the time each box was clicked (reaction time) and the color of the box. So it makes it possible to compare clicking patterns among participants.
4 - I’m using random colors for the clickable boxes, from a conditions file. The loop randomizes the colors each time it runs the trials.
currentState = mouse.getPressed()[0]
if currentState and not lastState:
for clickable in clickables:
if mouse.isPressedIn(clickable):
clickedColors.append(clickable.color)
clickedTimes.append(clickClock.getTime())
clickedBoxes.append(clickable.name)
if len(clickedBoxes) > 0:
for clickable in clickables:
if clickable.name == clickedBoxes[-1]:
polygon.color = clickable.fillColor
lastState = currentState
The code is running great, but I couldn’t retrieve the clicks though. I have no problems running the experiment. However, checking the XLS data file generated it have the columns “box”, “color”, “RT” as follows:
box
[‘box1’, ‘box1’, ‘box3’, ‘box2’, ‘box1’, ‘box2’]
color
[<method-wrapper ‘getattribute’ of attributeSetter object at 0x0000024E634900A0>, <method-wrapper ‘getattribute’ of attributeSetter object at 0x0000024E634900A0>, <method-wrapper ‘getattribute’ of attributeSetter object at 0x0000024E634900A0>, <method-wrapper ‘getattribute’ of attributeSetter object at 0x0000024E634900A0>, <method-wrapper ‘getattribute’ of attributeSetter object at 0x0000024E634900A0>, <method-wrapper ‘getattribute’ of attributeSetter object at 0x0000024E634900A0>]
There are 6 repetitions on the experiment, so it is recording only the last clicked box? It would be nice to have all valid clicks on the boxes, as well the respective color of the box clicked and the time clicks occurred relative to the beginnig of the routine.
I tried changing mouse data to “routine” but it didn’t worked.
Concerning the color, maybe you have to change clickedColors.append(clickable.color) to clickedColors.append(clickable.fillColor) to extract the color as a string.
Probably I’m missing out something on generating the XLS file. The experiment have 5 repetitions (loop), but I don’t know if this file recorded all clicks during the entire experiment or just the last click of each repetition.
Thank you!! But I don’t know why Psychopy aren’t recording all clicks during the trials. I guess it is retrieveing only the last run of the trials loop.
I have only two question regarding the interpretations of the results. I used a likert scale made with a slider (no code). The results are the response (point on slider) and the response time (rt), but I don’t know how to interpret them, as they are labelled as big numbers.
Should I mark on the mouse to get the time relative to the routine instead of the experiment?
Could you confirm these high numbers by opening the csv file in a text editor? Sometimes Excel does weird things to numbers and there is no reason why these numbers should be this high.
This index tells you which row this condition has in the original conditions file.
Still don’t got what are these numbers. Are they the position of mouse on the slider, ranging from 1 to 10? And the .rt are the response times to click on the slider relative to the presentation of the slider?
.started and .stopped are the times on the experiment the mouse was started and stopped on a given routine?