Specifying a custom trial list in PsychoJS

URL of experiment:

Description of the problem:
Hello,
I am trying to convert a Psychopy experiment, created in Builder, to PsychoJS and run on Pavlovia. The Python custom code was working as it was supposed to but I converted the custom code to JS and I’m encountering an issue so I’m unsure where my syntax went wrong. What the first part of the experiment is meant to do is select a subset of possible .csv files for each participant based on a randomly generated number. However, it seems like the files aren’t reading in correctly and I’m not sure why. Before any images are displayed, this error message is displayed:

TypeError: Cannot assign to read only property ‘undefined’ of object '#'

I tried to define my list using the following:

if ((version === 10)) {
      cond = ["1_start_ver_10_walk.csv", "2_start_ver_10_walk.csv", "3_start_ver_10_walk.csv", "4_start_ver_10_walk.csv", "5_start_ver_10_walk.csv", "6_start_ver_10_walk.csv", "7_start_ver_10_walk.csv", "8_start_ver_10_walk.csv", "9_start_ver_10_walk.csv", "10_start_ver_10_walk.csv"];
      shuffleArray(cond);
      goal_list = ["ver_10_goals.csv"];
      trial_list = ["ver_10_trials.csv"];
  }
  cond1 = cond[0];

and then call on these lists in the TrialHandler:

 trials_1 = new TrialHandler({
    psychoJS: psychoJS,
    nReps: 1, method: TrialHandler.Method.SEQUENTIAL,
    extraInfo: expInfo, originPath: undefined,
    trialList: cond1,
    seed: undefined, name: 'trials_1'
  });

I’m not sure why this isn’t working or what the error is referring to.

Any help would be hugely appreciated!
Best,
Iva

You can isolate the line generating the error by opening your browser’s JavaScript console when it occurs. in Chrome, go to view->developer to find the console. My guess is that it’s actually not from this code element at all, but something else possibly in the trialhandler code that doesn’t like what you’re feeding it.

Thanks for your advice! The error message in the console unfortunately only pointed me to the line that generated the error message itself (i.e., the line that detects that ‘trials’ is undefined), so I haven’t completely figured it out yet, but I’ll keep trying. This helped me figure out that you were right in your guess though - the .csv files seem to be read in correctly but something else breaks down with the trialhandler.

If version doesn’t equal 10 then you don’t define cond so you can’t assign cond1