psychopy.org | Reference | Downloads | Github

How to use mouse click on button to end trial

#1

OS (e.g. Win10): OS X 10.14.4
PsychoPy version (e.g. 1.84.x): 3.1.0
**Standard Standalone? (y)
What are you trying to achieve?:

I have a routine with 6 different radio buttons. I want to set it up such that subjects must make a selection on each of the radio buttons before they can proceed, and of course so that they can change their answer on a button before proceeding.
So I created the radio buttons with the slider component, and added a shapeStim as a button, and have a mouse element that has the shapeStim as a clickable object.
Now, I obviously cannot have the mouse element set to end Routine on valid click, because that would mean subjects could bypass answering the radio buttons.
I have a piece of code that keeps track of whether all 6 radio buttons have had sections, and that piece definitely works. But when I manually want to check whether the shapeStim has been clicked, it does not work.

What did you try to make it work?:

if responseChecker >=6 and button in mouse.clicked_name:
    continueRoutine = False

in the above code, responseChecker is a variable that increments each time one of the radio buttons is selected (and then removes from the list to be checked); ‘button’ is the name of the shapeStim, and ‘mouse’ is the name of the mouse component.
When I add print (mouse.clicked_name), I only get [], even when I click the button.
I also tried using gotValidClick, but that also always remains FALSE.

Any pointers would be massively appreciated

Thank you!

#2

what about:

if responseChecker >= 6 and mouse.isPressedIn(button):
    continueRoutine = False

(and assuming that this code runs in the “each frame” tab.)

Har to say much else without seeing the rest of the code and where/when this code is executed relative to the rest.

#3

HI Michael,

Sorry about the delay in getting back to you — I didn’t have time to test this.

Magic — works exactly as needed!

Many thanks indeed!

Marc