psychopy.org | Reference | Downloads | Github

Alternative to .isPressedin()

I have a task in which mouse clicked in a circle draws a cross and stores the location of the click. This worked well in builder using following code I modified from someone else code. There is a custom function called makeCross involved.

Begin Experiment

def makeCross(pos):
    cross = visual.ShapeStim(win, pos=pos, depth=-2, vertices='cross', size=(0.05,0.05), lineColor=[-0.8, -0.8, 1], fillColor=[-0.8, -0.8, 1])
    cross.setAutoDraw(True)
    return cross

Begin Routine

crosses = []

Each Frame

if mouse1.isPressedIn(LocCircleBig,buttons=[0]):
    crosses.append(makeCross(mouse1.getPos()))
   

End Routine

for across in crosses:
        across.setAutoDraw(False)

When I tried the task in Pavlovia online it did not work. Some discussions in discourse mentioned that .isPressedin not available in online which is disappointing. So tried following instead in the each frame section:

if (LocCircleBig.contains(mouse1) && mouse1.getPressed()[0] === 1 ){
  crosses.append(makeCross(mouse1.getPos()));
}

This one did not work both in builder and online. In online I got the error attached as photo.! Any help would be very appreciated. Thanks!!

Screen Shot 2020-07-01 at 3.09.52 AM|690x415

Try

makeCross = function(pos):
    cross = visual.ShapeStim(win, pos=pos, depth=-2, vertices='cross', size=(0.05,0.05), lineColor=[-0.8, -0.8, 1], fillColor=[-0.8, -0.8, 1])
    cross.setAutoDraw(True)
    return cross

This might not be correct for Python code because my crib sheet contains functions in JS but not Python but hopefully you can see the principle

Did you mean put these code in python part of the code when in Auto>JS ?

makeCross = function(pos): 

Coz in python functions are always written in def somefunction(): of if it was meant to be js than makeCross = function(pos) { do something return something }

can you clarify please.
Thanks.

This one.