trials.thisN and trials.thisTrialN are constant in the online experiment

OS (e.g. Win10): MacOS 10.14.6
PsychoPy version (e.g. 1.84.x): 2020.2.4
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: implement a break

Hi all,

I know this problem has been coming up over and over, but I can’t find a solution. The fields trials.thisN and trials.thisTrialN won’t get updated in the JS script and remain constant (on 0). Therefore, I cannot implement a loop break to make participants rest after a certain number of trials. The script works flawlessly when I run it locally. The problem is only with JS.

Has this bug been solved yet?

Thank you!

1 Like

Hey @treelen, sorry to hear PsychoJS is giving you trouble, would it be possible to let me access your repo or send me a .psyexp so that I can investigate a bit further? Here to help, thanks, s.

I think it’s a new bug in 2020.2

I can’t get .thisN to work either.

1 Like

Thank you for your answers.
Would you have any suggestion to bypass the problem?

Hi @thomas_pronk, is this something the dev team are aware of? There might have been long-standing loop-related issues, but getting consistency between the desktop and online versions would be important for this functionality.

I wasn’t aware of this. Thanks for the headsup @wakecarter and @Michael.

I think there are a couple of lessons to be learned here; I’ll first do a pitch in our daily before going deeper.

Meanwhile I found a list of standard attributes over here: https://www.psychopy.org/api/data.html#psychopy.data.TrialHandler

I already built an e2e test for looping; I’ll add checks for these attributes in this test.

1 Like

@wakecarter, we’d like to be sure whatever you address gets picked up by us promptly; be welcome to get directly in touch (via e-mails or our Teams workspace)

I think we’re being bit by the same problem. We are trying to set a stimulus based on a list whose length is the same as the number of trials. Is there any update on this issue? (Sorry if I failed to find a relevant post.)

What version are you using? This may have been fixed in 2021

We were using v.2021.1.2. I updated to v2021.1.4. The behavior still seems to be the same. Here’s the web console log:
TypeError: graphs[trials.thisN] is undefined

trialRoutineBegin https://run.pavlovia.org/jzacks/exp2002_jz/html/Exp2002_1_210407.js:696

_runNextTasks https://run.pavlovia.org/jzacks/exp2002_jz/html/lib/util-2021.1.4.js:1560

_runNextTasks https://run.pavlovia.org/jzacks/exp2002_jz/html/lib/util-2021.1.4.js:1564

_runNextTasks https://run.pavlovia.org/jzacks/exp2002_jz/html/lib/util-2021.1.4.js:1564

update https://run.pavlovia.org/jzacks/exp2002_jz/html/lib/util-2021.1.4.js:1514

core-2021.1.4.js:1923:12

onerror https://run.pavlovia.org/jzacks/exp2002_jz/html/lib/core-2021.1.4.js:1923

Following up, does anyone know if this is still broken in v2021.1.4? If so, is there a way to downgrade to workaround?

There have been some changes in how loop variables work in newer versions of PsychoJS. Try using this variable instead: snapshot

Now, it will have most properties you’re after (like snapshot.thisN), but there is some room for improvement, since it doesn’t have all the properties that PsychoPy offers, and it will complicate things with nested loops. I made a little test to illustrate these issues, for when we’ll go optimize this. Likely to take a while though, since we’ll probably bundle this up with some other upgrades of the looping system.

Thanks, Thomas. I think that did the trick. (It breaks the experiment running locally in python, though.)

2 Likes

Yeah, sorry about that. We’ll indeed need to improve this! :slight_smile:

No worries; I just wanted to make sure you and thread readers were aware!

1 Like