BART, online, pavlovia

Hi everyone,

I am actually working on the Pavlovia’s BART task with the aim to use mouse responses rather than keyboard ones and to use it online. I added a mouse component to my trial routine asking to participant to click on a pump text (for inflate the balloon) or a bank text (to transfer the money to the permanent bank). I change the code to pump as follow:

The problem is that nPumps don’t work properly. With each mouse press, the balloon inflates (and consequently the gain) with values greater than those described by the code. Where could my mistake be?

Previously I tried with this code which locally work well

but once uploaded online, I received the following error message “mouse is not a constructor” so I decided to try other solutions.



does this help?

Best wishes Jens

Thanks @JensBoelte!

Unfortunately, I have tried following these solutions but cannot resolve the above issues. I added a mouse component and used the code (as above) following the post you kindly posted. I assume there is some bug regarding the “nPumps=nPumps+1” part of the code, but I can’t figure out how to fix it and why it persists.


Hi @lorenzo.brienza,

I think the code is inflating nPumps for the duration that the mouse is pressed, instead of only once per “click”. You can add additional code to keep track of mouse state to avoid this behaviour. Something like the following should do the trick:

In Begin Routine

mouse.clickReset() #resets mouse state
mouseup = True #the mouse is not clicked yet

In Each Frame

if mouseup and 1 in mouse.getPressed(): #mouse must change from "up" to "down" i.e. a "click"
        mouseup = False #mouse is now down

        if mouse.isPressedIn(LOCATION_1):
            #DO STUFF
        elif mouse.isPressedIn(LOCATION_2):
            #DO SOMETHING ELSE

else: #mouse is being held down
    if not 1 in mouse.getPressed(): # mouse button has been released
        mouseup = True

I tested this in PsychoPy 2022.2.4. Other versions may behave differently.


1 Like