PsychoJS equivalent of PsychoPy .next()?

I have a general question about the trialHandler's command .next() in PsychoJS.

Does anybody know what its PsychoJS equivalent is? I can’t find it in the API list of commands.



I’m also curious about this. I’m struggling to understand the .next() command on PsychoJs.
I’m loading an excell file and grabbing a random row on each trial

On Python it works as follows:

when I initialise, I load my conditions and hand them over to the trialHandler

trialList=data.importConditions(‘TripletList - Copy.xlsx’)
trials = data.TrialHandler(trialList,1, method=‘random’,
dataTypes=None, extraInfo=None, seed=None, originPath=None,

On each trial I grab the values associated with my 4 variables (s1-3, emotion) in the new trial (randomly selected)

thisTrial =

this is how I’ve set this up in Js. I found mention of a NEXT instruction… but apparently I’m not using it correctly. This crashes because ‘thisTrial’ returns as ‘undefined’

trials = new TrialHandler({
psychoJS: psychoJS,
nReps: 1, method: TrialHandler.Method.RANDOM,
extraInfo: expInfo, originPath: undefined,
trialList: “TripletList - Copy.xlsx”,
seed: undefined, name: ‘trials’});

thisTrial = trials.NEXT

Any suggestion how to get this to work in PsychoJs?

I’m working on a demo which needs this and was surprised to find that there haven’t been any answers in the forum that I can find.

As indicated elsewhere

thisPath =; leads to the error that .next is not a function and
thisPath = myPaths.NEXT; doesn’t give an error but thisPath is then undefined.

The demo I’m working on is set to public

Any ideas @sotiri ? I could use a workaround by adding an index variable but we do need an answer about .next().

Interesting, thanks for flagging @wakecarter, OK let me take a look, x

Hi there,

Would getFutureTrial(n) achieve what you need? returns info on the nth future trial JSDoc: Class: TrialHandler

Hope this helps,

Good hunch @Becca, thanks. As it happens calling next() on the TrialHandler instance is meant to update internal stats, such as thisIndex as well as returning the current trial and so getFutureTrial() would only work the first run. Fortunately, exposing the [Symbol.iterator] used under the hood with TrialHandler.forEach() does the trick. Please note however @wakecarter that auto-translating works for Begin Routine and only partly for Each Frame because of the number parsing required to derive pathStart. You can find the details in the support fork, in particular the Before Experiment tab, but a permanent fix should be included with the next release, x

1 Like

Thanks. Please could you add me (Wake) to the support fork so I can see it?

Yes of course, sorry, should be OK now :blush:

1 Like

Thanks @sotiri . You might be interested in my new variation. The only Both code I’ve got in the trial routine is translating pathN = myPaths.thisN to pathN = myPaths.getTrialIndex()

1 Like

No problem, looks good yes, x