ShapeStim won't disappear once the trial routine ends

URL of experiment: Pavlovia

Description of the problem:
My group is currently trying to develop a trail making experiment for use on The objective is to lead the mouse cursor over various targets in the order specified. An example image of how our experiment looks like is below:

However, once the trial ends and the loop starts over again, the lines do not disappear. An example of what this looks like is below:

Here is the segment of code that controls the line making:

drawLine = function (shapeList) {
      var lines, pos1, pos2;
      lines = [];
      if ((! (shapeList.length % 2))) {
          while (shapeList.length) {
              pos1 = shapeList.pop();
              pos2 = shapeList.pop();
              var newLine = new visual.ShapeStim({ 
                  win: win,
                  vertices: [ pos1.pos, pos2.pos ],
      if (lines.length) {
          for (var line, _pj_c = 0, _pj_a = lines, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
              line = _pj_a[_pj_c];

Essentially, a new ShapeStim is created once 2 points are put into the array, and this makes a line between the targets. So far, we are not sure how to remove the lines once the routine ends, nor are we sure as to how the other routine components get removed once the routine ends.

For those who try the online version, apologies for the lagging experiment, we are planning to create a new version once we solve this issue. The software platform is PsychoJs, the platform version is 2020.2.

Edit: The experiment also seems to work fine offline through PsychoPy v2020.2.3 as far as I can tell.

Any help is appreciated.

In end routine you might need to set line auto draw to false and then do a win.flip()

1 Like

You shouldn’t do a manual win.flip(): it will break Builder’s ability to count frames.

I’m not a JavaScript person, and don’t know the context in which this drawing function is called, but I imagine you just need to reset the list of vectors to empty in the “Begin routine” tab, so that nothing carries over to be drawn from the end of the previous trial.