| Reference | Downloads | Github

PsychoJS loop not breaking


I have a problem with my online PsychoPy experiment. Here is my setup: participants read some instructions, and then undergo a training during which they have to answer 8 questions. I set a nested loop and a treshold that send them back to the beginning of the training if they perform less than 60% (around 5/8 questions). It works fine locally, but when I take it online, we get stuck in the loop. So even if the participant have 8/8, the training starts again.

I tried modifying the JS script manually, and replace the last bit to trials.finished=true; (also tried .finished = true; and currentLoop.finished = true;), as suggested in other discussions, but nothing works. Any ideas ?

Hi There,

I think this could be because you are using .thisN which version of PsychoPy are you using?

Hi Becca !

I’m using v2020.2.10

Aha! OK how far deep into task development are you? You should be able to use thisN in the newest release - which might fix your issue Releases · psychopy/psychopy · GitHub

Alternatively - use a custom trialcounter - add a code component, in the begin experiment tab type trialCounter = 0 then in the end routine tab type trialCounter += 1 then you can use that variable instead of thisN

Hi Becca,

Thank you for your answer. I downloaded the new release. The experiment still works fine locally, but now I get this error message when trying to do it online:

Capture d’écran 2021-07-26 à 09.51.54

With the previous version, I didn’t have this error. The files are stored correctly in the html/resources folder. Don’t know what to do from here…

Alternatively, I tried your suggestion about the custom trial counter, but I may have done something wrong. When trying to launch the experiment locally, I get this error message:

File “/Users/Nadia/Library/Mobile Documents/com~apple~CloudDocs/SISSA/MR/Pilot/”, line 2512, in
if ctrl_training_inner.trialCounter == 0:
AttributeError: ‘TrialHandler’ object has no attribute ‘trialCounter’

Experiment ended.

This are my code components:

Just use trialCounter, not ctrl_training_inner.trialCounter.

Sorry about that. I am very new to this. I did that change:

still have this error:

File “/Users/Nadia/Library/Mobile Documents/com~apple~CloudDocs/SISSA/MR/Pilot/”, line 2725, in
if trialCounter + 1 == trialCounter.nTotal:
AttributeError: ‘int’ object has no attribute ‘nTotal’

Experiment ended.

Thank you for your help !

trialCounter is a simple variable which you are starting at zero and adding 1 to each loop. It therefore doesn’t have and .nTotal method. You need something along the lines of

if trialCounter + 1 == nTrials:


if trialCounter + 1 == 20: