Wakefield's Daily Tips

ReferenceError: currentLoop is not defined

Although very similar to ReferenceError: varName is not defined currentLoop and frameDur are key PsychoJS variables and this error indicates a compilation error.

The lines

var currentLoop;
var frameDur;

should appear above

async function updateInfo() {
  currentLoop = psychoJS.experiment;  // right now there are no loops
  expInfo['date'] = util.MonotonicClock.getDateStr();  // add a simple timestamp
  expInfo['expName'] = expName;
  expInfo['psychopyVersion'] = '2024.2.4';
  expInfo['OS'] = window.navigator.platform;

The most likely cause is JavaScript that is incompatible with PsychoJS, the risk of which can be reduced by using Auto → JS code components wherever possible.

For example, it appears that PsychoJS does not support optional chaining.

slider_value = document.querySelector('input[name="expectation"]:checked')?.value;

A clause of this type should should be replaced with simpler syntax.

let selectedInput = document.querySelector('input[name="expectation"]:checked');
let slider_value = selectedInput ? selectedInput.value : null;