From b9228bc65f76fb238d52bdf6882f057a0d2729ff Mon Sep 17 00:00:00 2001 From: Alain Pitiot Date: Mon, 21 Jun 2021 14:33:22 +0200 Subject: [PATCH] fromSnapshot now creates a global variable for the trial, such that loop.thisTrial['field'] === thisLoop['field'] --- src/data/TrialHandler.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/data/TrialHandler.js b/src/data/TrialHandler.js index 23606ab..47b75a4 100644 --- a/src/data/TrialHandler.js +++ b/src/data/TrialHandler.js @@ -271,8 +271,8 @@ export class TrialHandler extends PsychObject { this._psychoJS.logger.warn(`attempt to replace the value of protected TrialHandler variable: ${attribute}`); } - snapshot.trialAttributes = trialAttributes; } + snapshot.trialAttributes = trialAttributes; // add the snapshot to the list: this._snapshots.push(snapshot); @@ -317,6 +317,7 @@ export class TrialHandler extends PsychObject return; } + snapshot.handler.nStim = snapshot.nStim; snapshot.handler.nTotal = snapshot.nTotal; snapshot.handler.nRemaining = snapshot.nRemaining; @@ -329,11 +330,22 @@ export class TrialHandler extends PsychObject snapshot.handler.thisTrial = snapshot.handler.getCurrentTrial(); - // add to the trial handler the snapshot's trial attributes: + + // add the snapshot's trial attributes to a global variable, whose name is derived from + // that of the handler: loops -> thisLoop (note the dropped s): + let name = snapshot.name; + if (name[name.length-1] === 's') + { + name = name.substr(0, name.length-1); + } + name = `this${name[0].toUpperCase()}${name.substr(1)}`; + + const value = {}; for (const attribute of snapshot.trialAttributes) { - snapshot.handler[attribute] = snapshot[attribute]; + value[attribute] = snapshot[attribute]; } + window[name] = value; }