Clickable text fails

I think that your mouse component is actually called startMouse.

What component is named obj?

What custom code do you have that refers to an object of that name?

My guess is that you have a stimulus called obj but then also some custom code that redefines that name to point to a list.

I didn’t write any custom code for this. I’m following along the video from the workshop that was given the other week, so I’m using everything via the builder - so I’m not sure where obj is coming from.

These are the only components that I have

OK. Perhaps best if you post your .psyexp file here for us to look at.

posnerTarget.psyexp (17.0 KB)

Hopefully this is helpful. I’m using the example files listed on the workshop website for reference

OK, that’s really weird - you’ve come across a bug in PsychoPy itself that must be new and definitely shouldn’t be happening.

Hi Todd, @TParsons this might be one for you. Builder (v 2021.1.0) generates this code when checking if a stimulus contains a mouse click:

for obj in [[image, image1]]:
    if obj.contains(mouse):

i.e. the stimuli to be checked are nested within a list within a list, so obj.contains() will always fail when iterating over the elements of the outer list, as it only sees it containing one entry, which is a list rather than a stimulus. Seems odd that no other users have been hit by this though, as it should be a show-stopper for many (unless I’ve missed it)?

Okay thanks @Michael for letting me know. I will wait to hear back from you all about whether it’s fixed before doing anything else!

if nextButton.contains(startMouse):

Thanks for your response @wakecarter, it makes sense that obj should be nextButton. Unfortunately obj seems to have been set due to the bug.

You could remove nextButton from clickable stimuli and add my suggested code into the Each Frame tab of an auto translated code component.

Okay I can try this today! Thanks

Actually I think my code will count a hover. I use that form of code for mobile devices. For a click use if startMouse.isPressedIn(nextButton) or end the routine on any click and then check using contains in End Routine.

Ah, I see where this has come from! As conversion to a list is now handled by the parameter’s innate string conversion, the bit of code in Mouse which adds a [] is no longer needed, it adds [] around what is already a list… It’s an easy fix, so will put that in for the next bugfix release :slight_smile:


Thanks @TParsons ! Should I fix this in my code for now just so that I can keep moving ?

I think the best solution for now (and we’re talking just a few weeks at most, as we’ll be releasing minor versions fairly regularly as these little bugs crop up) is to leave “clickable stimuli” blank and instead add a Code component with this bit of your code:

if sum(buttons) > 0:  # state changed to a new click
    # check if the mouse was inside our 'clickable' objects
    gotValidClick = False
    for obj in [nextButton]:
        if obj.contains(startMouse):
            gotValidClick = True
    x, y = startMouse.getPos()
     buttons = startMouse.getPressed()
     if gotValidClick:  # abort routine on response
          continueRoutine = False

copied into the Each Frame tab - essentially simulating what the Mouse component does, but editable at the code level.

This also doesn’t affect the Button component, so you could also replace startMouse and nextButton with a Button component and this would do the same thing.

1 Like

HI @TParsons sorry for all of the questions but I’m a new psychopy user. So I can make this modification as you suggested but the problem is that I don’t have a coder view in my psychopy. If I go to view in the builder dropdown menu, there is no option to view coder. If I change my preferences so that it automatically opens the coder when I open psychopy, it still just opens the builder. Is this a macOS problem? Should I re-download psychopy?

This is all done within the Builder view. Go to the component panel and inside the “Custom” section, you’ll see a “Code” component icon. Click that. It has tabs for various times during the experiment when custom code will run (e.g. at the start of the experiment, at the beginning or end of a routine, and so on).

Take the code suggested by Todd and paste it into the “each frame” tab, so that it will run on every screen refresh (typically 60 times per second).

This saves you from directly editing the generated Python script in the Coder view, which can be difficult and unwieldy.


Ah thank you! I understand, thanks for the explanation.

Hi everyone,

I keep running into the same problem every now and then. Weirdly, it works in some experiments…
However, I checked the py code of my current experiment and saw the double brackets around my list of clickable stimuli.
I tried the code as work around but it didn’t work in my case. I get an Indentation error, whenever I leave the clickable stimuli prompt empty.
Looking at the py code, it just looks like the code git cropped, which causes indentation errors in the next line.

        if Prac_mouse.status == STARTED:  # only update if started and not finished!
            buttons = Prac_mouse.getPressed()
            if buttons != prevButtonState:  # button state changed?
                prevButtonState = buttons
                if sum(buttons) > 0:  # state changed to a new click

Did anybody else encounter this problem?
Is there a way to change the way the list is converted?

Thanks in advance.

Best, Kathrin