jspsych/A2timelinevars.html 2024-12-10
// classic, combine timeline and type classic = { type: 'html-keyboard-response', timeline: [{stimulus: "c 0"}, {stimulus: "c 1"}], } text = { type: 'html-keyboard-response', stimulus: () => ("block: "+jsPsych.timelineVariable("block") + ", stimulus: " + jsPsych.timelineVariable("stimulus")) } // nested timeline: vars0 = [{stimulus:"a 0"}, {stimulus: "a 1"}] vars1 = [{block: 0}, {block: 1}] nestedBlock = { timeline: [text], timeline_variables: vars0, } block = { timeline: [nestedBlock], timeline_variables: vars1, } // dynamic timelines, use sampling function for this behaviour indices = [0,1,0,1] dynamic = { timeline: [text], //timeline_variables: () => [vars0[1], vars0[0]], // NOT ALLOWED, use sample timeline_variables: vars0, // sample: { type: 'custom', fn: (t) => indices.map((i) => t[i]) // t is the index array } } addEventListener("load", async () => { jsPsych.init({ timeline: [classic, block, dynamic], // block/dynamic/classic on_finish: async function() { jsPsych.data.displayData() } }) })