I'm trying to program an experiment with the JavaScript package JSPsych. The MWE of my experiment is supposed to do the following: The participant enters a letter in a survey-text trial and in the following html-response trial, this letter is supposed to be presented to the participant as a stimulus.
My problem is that I can't find a way to access the input of the participant in the survey-text trial. My program structure follows the reaction time tutorial on the JSPsych website: The trials are being created one after another and pushed into a timeline
array which is being initiated at the very end of the code. What that means is that at the time the trial is being defined the user has not input anything yet.
My MLE code can be found below. While running the experiment in a browser I am able to access the data from the survey-text trial with JSON.parse(jsPsych.data.getLastTrialData().select('responses').values).favorite
. However, in the code below this produces the following error: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
, because (I strongly presume) there is no last trial at the time the code is being compiled.
let letter_display, letter_survey, test_procedure, timeline;
timeline = [];
letter_survey = {
type: "survey-text",
questions: [
{prompt: "What is your favorite letter?", name:"favorite"}
],
}
timeline.push(letter_survey);
letter_display = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('stimulus'),
};
test_procedure = {
timeline: [letter_display],
timeline_variables: [{type:'html-keyboard-response', stimulus: JSON.parse(jsPsych.data.getLastTrialData().select('responses').values).favorite}]
};
timeline.push(test_procedure);
jsPsych.init({
timeline: timeline
})