Saving mouse position for every frame in online experiment

URL of experiment: https://run.pavlovia.org/isabelbenvenuti/exp_1/html

(This is a language experiment in Spanish. Please let me know if it would be helpful for me to provide translations of the instructions.)

I am trying to run an online experiment that tracks mouse position on every frame of a routine. Participants see four images and hear a sentence that mentions one of the images. Then the position of their mouse is tracked as they click the correct image mentioned by the audio.

In the csv file generated after running the experiment, the lists of x and y coordinates containing mouse position data each contain only one element. However, when I run the experiment from the builder, position data for every frame is saved.

Any ideas on how to fix the issue? Thanks!

Buenas!

I haven’t had time to look at your experiment but I had exactly the same issue. After looking at it for a while I realised that pavlovia only records the position when there’s a mouse click. Since I basically know nothing about Java, what I’ve done is to put a code component saving the data, and it seems to work, yay!
So here is what I made:

In begin routine I wrote the following in Python:
x_coord = []
y_coord = []

Which translates into Java:
x_coord = [];
y_coord = [];

In each frame for Python:
x_coord.append(mouse_response.getPos()[0])
y_coord.append(mouse_response.getPos()[1])

For Java:
mouse_position = mouse_response.getPos();
x_coord.push(mouse_position[0]);
y_coord.push(mouse_position[1]);

And in end routine in Python:
thisExp.addData(‘x_coord’, x_coord)
thisExp.addData(‘y_coord’, y_coord)

And in Java:
psychoJS.experiment.addData(‘x_coord’, x_coord);
psychoJS.experiment.addData(‘y_coord’, y_coord);

It worked for me, hope it can help!

5 Likes

Thanks! I also needed to track time on each frame, so I ended up fixing it by adding the following to the mouse updates in the JS code:

  const position = mouse_4.getPos();
  mouse.x.push(position[0]);
  mouse.y.push(position[1]);
  mouse.time.push(mouse.mouseClock.getTime());
2 Likes

Hi, also trying to do mouse-tracking online and have multiple issues with the code.
Did any of you randomize the position of the stimuli, and if so, what code did you use for that? Thanks!

Hi Alonset,

Thanks for the code but it did not work when I try to run it online.

I’m totally new to psychopy and here is what I did: insert a code component in the routine which contains the mouse component. My question is: do I need to change the setting in the mouse component concerning the status recording (i.e., choose to save data for every frame)? Or should i switch the mouse component to ‘never’ recording the status data?

Thanks for your kind attention