# PsychoJs.NEXT - Help!

**URL:** <https://discourse.psychopy.org/t/psychojs-next-help/15668>\
**Category:** Online experiments\
**Created:** [August 12, 2020, 3:04pm UTC](https://discourse.psychopy.org/t/psychojs-next-help/15668 "2020-08-12T15:04:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicola\_Binetti](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nicola_binetti/32/6087_2.png) [@Nicola\_Binetti](https://discourse.psychopy.org/u/Nicola_Binetti)\
**Post date:** [August 12, 2020, 3:04pm UTC](https://discourse.psychopy.org/t/psychojs-next-help/15668/1 "2020-08-12T15:04:35Z")

</div>

URL of experiment: [https://pavlovia.org/nicolabinetti/triadcomparisonweb](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!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [August 12, 2020, 6:58pm UTC](https://discourse.psychopy.org/t/psychojs-next-help/15668/2 "2020-08-12T18:58:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nicola\_Binetti](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nicola_binetti/32/6087_2.png) [@Nicola\_Binetti](https://discourse.psychopy.org/u/Nicola_Binetti)\
**Post date:** [August 12, 2020, 9:25pm UTC](https://discourse.psychopy.org/t/psychojs-next-help/15668/3 "2020-08-12T21:25:39Z")

</div>

> [@Nicola\_Binetti](#):
>
> .NEXT

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

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [August 12, 2020, 9:42pm UTC](https://discourse.psychopy.org/t/psychojs-next-help/15668/4 "2020-08-12T21:42:20Z")

</div>

Shouldn’t it be `.next()` ?

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

---

<div class="post-metadata">

**Author:** ![Nicola\_Binetti](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/nicola_binetti/32/6087_2.png) [@Nicola\_Binetti](https://discourse.psychopy.org/u/Nicola_Binetti)\
**Post date:** [September 2, 2020, 11:26am UTC](https://discourse.psychopy.org/t/psychojs-next-help/15668/5 "2020-09-02T11:26:45Z")

</div>

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!!
