0

I am programming a task-switching experiment in javascript using the jsPsych library (jsPsych 6.0.5). I use a predefined list with stimulus attributes but I can't seem to link the specific values to variables in the data argument (output of data is undefined).

I am using a for-loop to link these values to the data argument, but that doesn't seem to be working. In the sample here below the first for-loop reads in the different columns of the predefined list, with each row representing a single trial. In the second for-loop, I try to input these values for each trial (row) to the data argument of my test_stimuli

for(this_trial = 0; this_trial < blocks[0].length; this_trial ++){
    curr_trial = blocks[0][this_trial];
    modality[this_trial] = curr_trial[6];
    cresp[this_trial] = curr_trial[10];
    perc_stim[this_trial] = [];
    for(j = 0; j < 4; j++){perc_stim[this_trial][j] = curr_trial[11 + j];};
    probe[this_trial] = curr_trial[15];
    condition[this_trial] = curr_trial[16];
  }

  for (i = 0; i < blocks[0].length; i++) {
    test_stimuli[i] = [{
        image: `<img src="images_a/${perc_stim[i][0]}.bmp" class = "training1"/>`,
        data: {
            correct_response: [cresp[i]],
            modality: modality[i],
            trial_id: 'stim'
        }
    }];
  }

When I log the data argument to the console, I get "undefined" (even though it logs the correct values when looking at for example the cresp array).

  • What statement are you using to log the data argument to the console? – Josh Feb 15 '19 at 15:16
  • 1
    @JoshdeLeeuw I use console.log() together with the the jsPsych call function for the data parameter, e.g. console.log(jsPsych.data.get().last(1).values()[0].correct_response) – Sam Verschooren Feb 17 '19 at 17:32
  • Where in the code do you run the console.log? I'm asking because a frequent mistake with jspsych code is to run experiment-dependent code before the experiment is complete, and I want to try and rule out easy explanations first. – Josh Feb 18 '19 at 18:11

0 Answers0