PsychoJs.NEXT - Help!

URL of experiment: https://pavlovia.org/nicolabinetti/triadcomparisonweb

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,
autoLog=True)

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

thisTrial = trials.next()
emotion=thisTrial[‘emotion’]
s1=thisTrial[‘s1’]
s2=thisTrial[‘s2’]
s3=thisTrial[‘s3’]

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
console.log(thisTrial)
emotion=thisTrial[‘emotion’]
s1=thisTrial[‘s1’]
s2=thisTrial[‘s2’]
s3=thisTrial[‘s3’]

Any suggestion how to get this to work in PsychoJs?
Thanks!

Don’t define it as trials in code. That variable name is reserved. Call it something else.

Thanks. Tried that, but it doesn’t seem to solve the issue.

Now I have:

thisTrial = myTrials.NEXT
console.log(thisTrial)
emotion=thisTrial[‘emotion’]

error on last line: “Cannot read property ‘emotion’ of undefined”

It seems I’m not using the .NEXT instruction correctly, so it’s outputing an undefined variable… but I can’t find it documented anywhere…
Any suggestion?

Thanks

Shouldn’t it be .next() ?

This isn’t something I’ve got much experience with.

Hi! Just came back to this… tried .next(), as well as .NEXT()… nothing.

note that with .next() I get a slightly different error:

  • TypeError: myTrials.next is not a function
    (note that at the crashed line I have: thisTrial = myTrials.next())

I had come across .NEXT (followed by no parenthesis) in a psychoJs script on gitLab some time ago, with no description: when I tried running that I was getting a different error: i.e. it didn’t seem to crash on the NEXT command per se, but the output was undefined (please see post above). Maybe a relevant clue…

Could any of the developers please assist me on this? It looks rather trivial … but I just can’t find any info on how to use this function.

Thanks!!