PsychoPy version (v2020.2.8):
I would like to draw a small rectangle on my clickable stimuli, when the mouse is pressed on these stimuli.
I try to do it like this:
There is no error message, but it also doesn’t show the rectangle.
Any help is greatly appreciated. Thanks!
Make a shape component in builder
Your code to check if the mouse is pressed is currently in the “begin routine” tab. That means it will only run once per trial, before the routine has actually started. You want that specific bit of code to run in the “Each frame” tab instead, so that it runs on every screen refresh (typically 60 times per second).
But note that inserting
core.wait(2.0) will completely break a Builder script’s timing. Builder assumes that the screen is being updated on every screen refresh - so during a trial, you shouldn’t run any custom code that will take more than one screen refresh (typically 16.666 ms). So
core.wait() should be forbidden in Builder scripts. If you use the code as-is, it might visually look like it works, but there could be very unpredictable results in the data.
You’ll need to find an alternative approach to have the stimulus display for two seconds - explain what the sequence of events should be and we can give suggestions.
Lastly, as Sal suggests - you don’t need to define the rectangle in code - you can create it via a Builder component but just set its opacity to be zero so it won’t display until you tell it to. The custom function
waitForMouse() likely will also not be necessary.
I see, thank you!
I’ll try again to describe what I would like to do: I would like to start a stimulus (polygon) under the condition that a valid mouse click has taken place before at this position. (I want the participant’s choice to be marked with a transparent ractangle for a few seconds)
I could create a shape component in the builder and let it start under a condition e.g. mouse.getPressedIn(three) (three is a clickable stimuli), but I think this is not a legal condition… Maybe there is another possibility to integrate this condition?
Are you just wanting the participants to see what they clicked? Like could an outline work? You could just make the shape component and set the line width to be
$outline and set it as
outline = 0 in the ‘Begin Routine’ tab. Then in the ‘Each Frame’ tab of your code write:
if mouse.isPressedIn(one) :
outline = 2 #or whatever size you want the outline to be
If you instead want to mess with the transparency of the shape, you can do the same thing in the ‘opacity’ box in the shape component.
Yes, that’s all I wanted to do. It works now! Thank you so much !
I have an experiment that uses builder to provide instructions to the participant, gather responses from the participant etc., and sends triggers to an ADinstruments power lab using a c-pod using a bit mask. (The bit mask is used to tell LabChart to automatically drop a comment on the ongoing ECG trace of LabChart file). All of this works great.
Here is the issue. I have set the psychopy window size to be half the size of the monitor (and is visible on the left half of the monitor). The program calls a website containing a simple computer game which appears on the right side of the monitor.
I want to time when I send the bit mask. In other words I want to wait until the person clicks to initiate the playing of the game on the right side of the monitor. I thought of using clickable stimuli for this purpose, but the problem is the clickable stimulus would be OUTSIDE of the psychopy window that I have defined.
Does anyone see anyway around this? Can you have clickable stimuli outside of a PsychoPy window?
You can try.
Alternatively, you might be able to use the mouse coordinates.