| Reference | Downloads | Github

[ISSUE] Trialhandler does not work properly online (trialList, thisN, thisTrialN issues)

URL of experiment:


Description of the problem:

On my main experiment I have had issues with using thisN and thisTrialN attributes. As we have discussed here: trials.thisTrialN does not get correct trial number in javascript

EDIT: The fix is to use “trials” instead of custom names for the loops, however then trialList doesn’t work when I do this.

Seems like the trialList attribute also has some issues. On my main experiment I was using shuffle to put some randomization in place however it threw an error Cannot read property ‘length’ of undefined.

So I hopped in to test why this could be and it seems like there are some bugs with the trial handler overall. For example at the experiment I have provided, which works fine offline, the trialList is “undefined” for the first loop but the trial numbers are reported correctly. For the second loop, the trial numbers are correct but the list is not.

I believe the errors with the trialhandler happens after adding your second loop to the experiment. Not a loop within a loop, but in general adding a new loop to any routine.


  • Make a new experiment.
  • Add first loop with conditions file, debug the trial number etc.
  • Add a second routine with a different conditions file, with a different loop and debug the trial number etc.
1 Like

Alright. A2A, I have found the solution.

  1. Use the custom loop name (defined by yourself) if you will use trialList
  2. Use the “trials” loop name if you will access attributes such as thisN , thistrialN and finished
  3. You can use both in the same loop with no issues, as far as I have tested.

NOTE: When you do these work-arounds, your experiment will not work offline. So you will need to comment the online experiment code out while doing local testing.

1 Like

You can also switch the code to Both so that you have different code locally and online


Since my issue is related, I’m posting here.

I’m trying to use trials.thisTrial with a dynamic variable name, i.e. trials.thisTrial[‘Var’+str(1)]. I’ve tried both trials and the custom loop name, in this case trialloop. trials.thisTrial results in a ‘is undefined’ error and trialloop.thisTrial in an error due to null. This makes me suspect that you also need to use the custom loop name for .thisTrial.
I was wondering how you are using trials.trialList and trials.thisTrialN in practice. It think it would help me getting access information in trialList or thisTrial.

PS: trials.trialList[trials.thisTrialsN][‘Var1’] is not even being initialized, so it doesn’t seem that I can use that instead. Edit: Not sure why, but now it works!

Try trials.trialList[trials.thisN]['Var'+str(1)]

In the end, trialloop.trialList[trials.thisTrialN][(“Var” + parseInt(1, 10).toString())] in JS worked as intended. So, custom loop name for .trialList and trials for .thisTrialN. Would advice to avoid .thisTrial - seems that it’s not parsing information.