Setting mouse location to a variable issues

URL of experiment: Pavlovia

Description of the problem: For my experiment I want participants to click on an image, and then a text object ‘x’ to display at the location of their click.

begin routine:

getLoc = 'undefined'

Each frame:

if (mouse.getPressed() == [1,0,0]) and getLoc is 'undefined':
    getLoc = mouse.getPos()

if (mouse.getPressed() == [1,0,0]) and getLoc is not 'undefined':
    clickmarker.setPos(getLoc)
    getLoc = 'undefined'

Text object:

It runs locally, but breaks online. I think the error is with how I am setting the position but I am not sure what I need to do to fix this.

Hi @Emma_L, do you receive an error message at all?

One issue will be with the conditional statements. They will never be true because you cannot compare arrays for equality in JavaScript in the same way as with Python. Instead, you could just index the values from the lists (i.e., mouse button list) and compare those instead. E.g.,

if (mouse.getPressed()[0] == 1) 
1 Like