| Reference | Downloads | Github

Loop issue: TrialHandler is set to 'finished' after adding trials to the loop's Scheduler - is it a bug?

Hi all,

I’ve managed to run the Stroop example locally on my machine (I’m using Ubuntu 18 and the experiment is run on a local Apache web server). However, I had to tweak the javascript generated by PsychoPy (2020.1.3) in a strange way in order to make it run.

One of the problems was that only one trial was executed, then the program directly moved to the end message. The generated csv file also contained only a single entry. This part of the code seemed to be responsible:

function trialsLoopBegin(thisScheduler) 
  trials = new TrialHandler({
    psychoJS: psychoJS,
    nReps: 1.0, 
    method: TrialHandler.Method.RANDOM,
    extraInfo: expInfo, 
    originPath: undefined,
    trialList: 'Trials.csv',
    seed: undefined, 
    name: 'Trials.csv'});

  currentLoop = trials;  // we're now the current loop
  // Schedule all the trials in the trialList:
  for (const thisTrial of trials) 
    thisScheduler.add(endLoopIteration(thisScheduler, thisTrial));
  return Scheduler.Event.NEXT;

I found that the trials are correctly added to the trial scheduler within the for loop (it contains the sequence of functions added in the loop N times). However, the loop breaks when the function endLoopIteration() is called for the first time. The reason is that the ‘finished’ attribute is set to ‘true’ already when the last trial is added to the scheduler in the for loop.

Inserting the following line after the for loop solved the problem for me:

currentLoop.finished = false;

But why is that? Why should I need to manually do that? Is it a bug?