There are plenty of questions and hints online about this kind of requirement, probably most relevantly here, but I still can’t get it to work, suggesting that I’m missing something simple.
In the experiment builder, I’,m editing the .js in the Begin Routine
section. I would like to set some parameters each routine, conditioned on the trial number. I therefore need the trial number, but I just can’t get hold of it.
Here is the function declaration and the first line
function Stim_PresentationRoutineBegin(snapshot) {
return async function () {
TrialHandler.fromSnapshot(snapshot);
Here is the list of things I have tried so far
trials.thisN;
trials.thisTrialN;
TrialHandler.thisN;
TrialHandler.thisTrialN;
TrialHandler.getSnapshot().thisTrialN;
snapshot.thisN;
and then reporting the output with console.log()
Trying getSnapshot()
declares that the function does not exist. For the other options I always get undefined
, except for the final option where ‘snapshot’ is NaN
.
I’m not clear what my mistake is then. Do I need to do something fancy to get the current trial number?