psychopy.org | Reference | Downloads | Github

Mouse click moves to next trial instead of dragging stimuli

OK, that’s strange, as the output shows that the right mouse button is detected, as
right_button_down = True happens, which means continueRoutine must also be set to False. Yet the routine doesn’t end. This implies that there must be some stray code somewhere that resets it to True. Can you once again post your .py file as it was when producing the output above, and hopefully we can hunt that down.

Sure, here it is.
test.py (15.5 KB)

OK, I’m flying a bit blind in this script, but from line 298 to 304 is this section:

            if mouse.status == STARTED:  # only update if started and not finished!
                buttons = mouse.getPressed()
                if buttons != prevButtonState:  # button state changed?
                    prevButtonState = buttons
                    if sum(buttons) > 0:  # state changed to a new click
                        # abort routine on response
                        continueRoutine = True #left click does not move to next phase
                  

I would guess that last line continueRoutine = True will simply undo the effect of the custom code I suggested, which sets continueRoutine to False when the right mouse button is pressed. Just try commenting out that line and see what happens.

If that fixes things, make sure to delete all of the temporary debugging print() statements - they will slow things down and impact on performance when running the task for real.

I tried doing that, and it seems to conflict with all the code directly below it:

            # check for quit (typically the Esc key)
            if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
                core.quit()
            
            # check if all components have finished
            if not continueRoutine:  # a component has requested a forced-end of Routine
                break
            continueRoutine = False  # will revert to True if at least one component still running
            for thisComponent in TrialPhaseComponents:
                if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                    continueRoutine = True
                    break  # at least one component has not yet finished
            
            # refresh the screen
            if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
                win.flip()

Which does not allow the experiment to run. However, if I set it to false, the trials do progress, but only do after clicking a mouse button 2-3 times per trial.

How?

I’m sorry, but at this stage you’re going to need assistance from someone local who understands Python to help you debug this. We can only usefully help remotely if people are using code components within the Builder interface, which ensures that custom code is inserted at the right place and doesn’t adversely affect the rest of the code structure. Since this experiment has been extensively manually edited, we can’t really usefully isolate anything remotely. You’ll need to do local debugging to follow the code logic.

It returns the following when I try to comment it out:

    if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
    ^
IndentationError: expected an indented block

But yes, I realize how difficult it’s become since the code was extensively manually edited. Thank you so much for your help thus far, I think I will be able to debug the rest myself, since my biggest issue was the mouse drag.

That particular error might be due to there being nothing following the if clause, when there should be at least one indented line after it, i.e. from the code posted above:

if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
    core.quit() # this needs to be present or else the `if` clause has no meaning.

or possibly the if line itself is not at the correct level of indentation - even if it looks OK, beware of mixing tabs and spaces. PsychoPy scripts should have all of their indents made of four spaces per level.

Ah yes, my mistake. I was able to get past that by commenting out the entire loop:

                    #if sum(buttons) > 0:  # state changed to a new click
                        # abort routine on response
                        #continueRoutine = True #left click does not move to next phase
                  

The routine is very close to working the way I intended it to. The only issue now is that it requires 5 right clicks for it to move on to the next trial. Thank you.

Debugging details:

Drag in process: True
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 0]
Drag in process: True
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 0]
Drag in process: True
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 0]
Drag in process: True
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 0]
Drag in process: True
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 1]
Drag in process: True
Button 2: 1
Right button down: True
Buttons:         [0, 0, 0]
Drag in process: True
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 0]
Drag in process: False
Buttons:         [0, 0, 1]
Drag in process: False
Button 2: 1

I was able to fix this.

        # -------Run Routine "TrialPhase"-------
        while continueRoutine:
            # get current time
            t = TrialPhaseClock.getTime()
            tThisFlip = win.getFutureFlipTime(clock=TrialPhaseClock)
            tThisFlipGlobal = win.getFutureFlipTime(clock=None)
            frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
            # update/draw components on each frame
            
            if mouse.isPressedIn(polygon, buttons=[2]): #right mouse button moves to next routine
                continueRoutine = False #right mouse advances trial
                
            if not drag_in_process: # check if one should be
                if mouse.isPressedIn(polygon):
                    drag_in_process = True
            
            if True in mouse.getPressed():
                if drag_in_process and mouse.getPressed()[0]: # left mouse button moves polygon
                    polygon.pos = mouse.getPos() # this gives you direct feedback anyway
                        
            else:
                drag_in_process = False  

Is what works perfectly. I cut out the right mouse button down component and replaced it with what I originally had for the right mouse button to move on to the next trial.