psychopy.org | Reference | Downloads | Github

trialHandler in nested loops

My experiment has the following visual flow of routines:

In this experiment, fmaskWarm, primWarm and targetWarm are presenting a given trial triplet. breakText contains a textComponent that appears after a given number of trials (in this code, every 2 trials) in loopWarm are presented. The routines in loopWarm2 are presented only after breakText. I have worked on the code together with @dvbridges and the code works locally in PsychoPy. Unfortunately, there are a couple of things that I do not seem to make it work in the JS side. I think the problem is related to the call for trialHandler's attributes like thisTrialN and commands like next(). From the github issue #49 solved by @apitiot, I gathered that the method .getSnapshot() is able to solve the problem.

As shown in the issue discussion, .getSnapshot() must be passed to the routine that uses trialHandler's attributes in the scheduler of the loop; the routine function then returns a function, which can access the given attributes. Intuitively, I used the getSnapshot() method in all routines that have at least one trialHandler's attribute:

  1. codeControlRoutineBegin() uses the command .next() to present the following trial in loopWarm without duplicates.
  2. targetWarmRoutineEnd() uses the attribute .thisTrialN to terminate loopWarm whenever I need to present a break.
  3. breakTextRoutineBegin() uses the attribute .nRemaining to count the remaining trials.
  4. fmaskWarm2RoutineBegin() uses the command .next() to present the following trial in loopWarm2 duplicates.

However, the script is not working. In particular, the command .next() does not seem to be defined. An error pops up saying:

TypeError: loopWarm.next is not a function. (In ‘loopWarm.next()’, ‘loopWarm.next’ is undefined)

When I try to use .next (without parentheses) instead, no error pops up, however the conditions under which breakText is supposed to show up are ignored, and the component appears only after loopWarm (the first inner loop) ends. Might it be something about .getSnapshot() that is causing the issue?

You can check out the code here; you can also check the psyexp file here: maskedPrimingDB_amended_original.psyexp (62.0 KB).

I hope everything is clear, but please do let me know if I need to clarify anything. I’d appreciate any help or suggestion! Thank you in advance!

Is anyone able to help?

Thank you in advance!