Add code generated visualstim objects to trialcomponents and scheduler

URL of experiment:

Description of the problem:
I have created a series of dots using a code chunk:

ndots = 5;
dots = [];

dots_lifeTime = [];
max_lifetime = 10/60;

dotsPos = [];

// Make dots:
for (var index = 0; index < ndots; index++) { 
    dots_lifeTime.push( Math.random()*max_lifetime);
    dotsPos.push([Math.random()-0.5,(index/ndots)-0.5]);
    dots.push(
       new visual.Polygon({
                win: psychoJS.window,
                name: "dot" + index,
                edges: 20,
                size: [0.01, 0.01],
                ori: 0,
                pos: dotsPos[index],
                lineWidth: 0,
                lineColor: new util.Color([0, 0, 0]),
                lineColorSpace: "rgb",
                fillColor: new util.Color([0, 0, 0]),
                fillColorSpace: "rgb",
                opacity: 1.0,
                interpolate: true,
            })
    );
}

I also set them to autoDraw:

dots.forEach( thisComponent => thisComponent.setAutoDraw(true) );

However, that only draws them once, and after updating their position, they just disappear. My guess is that they need to be added to the trialComponents, like other objects are:

    // keep track of which components have finished
    trialComponents = [];
    trialComponents.push(update_test);
    trialComponents.push(key_resp);
    
    for (const thisComponent of trialComponents)
      if ('status' in thisComponent)
        thisComponent.status = PsychoJS.Status.NOT_STARTED;
    return Scheduler.Event.NEXT;

Would that be the right way to go about it? Is there a better solution?

Interesting… after cleaning up the code for a more compact example, it works. No idea which line was the offending one that prevented this from working. :sweat_smile:

1 Like