So I thought maybe I have to add this var in the JS code of the experiment in line 421 after var instComponents;
but it didn’t help. I guess I’m acting incorrectly somehow.
var t;
var frameN;
var continueRoutine;
var _key_resp_allKeys;
var instComponents; instClock;
function instRoutineBegin(snapshot) {
return async function () {
TrialHandler.fromSnapshot(snapshot); // ensure that .thisN vals are up to date
//--- Prepare to start Routine 'inst' ---
t = 0;
instClock.reset(); // clock
frameN = -1;
continueRoutine = true; // until we're told otherwise
// update component parameters for each repeat
psychoJS.experiment.addData('inst.started', globalClock.getTime());
key_resp.keys = undefined;
key_resp.rt = undefined;
_key_resp_allKeys = [];
// keep track of which components have finished
instComponents = [];
inst_Components.push(key_resp);
inst_Components.push(textbox_3);
for (const thisComponent of instComponents)
if ('status' in thisComponent)
thisComponent.status = PsychoJS.Status.NOT_STARTED;
return Scheduler.Event.NEXT;
Just adding on to this as I have a similar issue. For me (and I believe also for the original poster), the “instClock.reset()” code is generated automatically by the routine rather than manually in a code component. (My routine is called “instructions” so the code for me is “instructionsClock.reset()”.
This code appears for every routine in the experiment, so I’m surprised it is causing an issue at all. Yet for some reason Pavlovia is expecting these variables to have been declared in advance.
EDIT: I’ve spotted that “instructionsClock” is in fact supposedly initialised in an earlier line:
async function experimentInit() {
// Initialize components for Routine "instructions"
var instructionsClock = new util.Clock();
// [then a bunch of other code]
Is the problem that “instructionsClock” is initialised inside the experimentInit() function and therefore treated as a local variable?
Quick update from me - I have found that the problem arises because I have a sound component that has no start time. The reason I did this is because I want the sound to play every time a key is pressed, rather than a fixed time in the routine.
When there is no start or end time included in the sound component, the first problem is an indentation error in the .js script, leading to the experiment being stuck on “initializing” in the browser. After manually fixing this (by shifting some of the code in the .js script and moving one of the } braces), it suddenly causes this error whereby a bunch of variables are not defined.
For me, I can resolve my issue by sorting out my sound component. For you, I have no idea if this is relevant to your issue at all. But at the very least, this shows that if you leave the start time blank in a component, it can cause many problems!