psychopy.org | Reference | Downloads | Github

Mouse not drawing on pavlovia experiment

URL of experiment: here is the gitlab project

Description of the problem:
Hi everyone,

I am quite new to javascript, and I’m trying to run an experiment where the user can draw bars on a blank graph using their mouse. I found another question on here that referred to drawing with the mouse, and I tried to make my code similar, but I am not sure why it is not working.

I have been having trouble getting the actual shapes to show up. I know that the mouse is working because I have been debugging and can clearly see that the mouse position is accurate.

I think it may have something to do with this block of code:

if (t >= 6.0 && blank_graph.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
blank_graph.tStart = t; // (not accounting for frame time here)
blank_graph.frameNStart = frameN; // exact frame index

  blank_graph.setAutoDraw(true);
  let buttons = mouse.getPressed();
  let left_button = buttons[0];
  if (left_button) {
      mouse_position = mouse.getPos();
      x_index = int((pos[0]+0.275)/0.01358)
      bar_objs[x_index].setAutoDraw(false);
      bar_objs[x_index].setHeight(pos[1]);
      bar_objs[x_index].setAutoDraw(true);
      bars[x_index] = pos[1];
  }
}

where bar_objs is an array of rect objects.

Please let me know if there is anything obvious. I really appreciate the help.

I don’t think setting autodraw to False and then True within the same frame does anything.

See if you can manipulate the bars with keyboard or time and add some print statements to work out which line is failing.

I found the bug. The problem was that in the if statement it checked that the status had not started, so it would only run the code once. After removing that condition, the code works as intended.

Thanks so much for the advice.