I want to use jsPsychHtmlButtonResponse to display a .txt-file from a local folder on my computer. The reproducible code below does not work, while a very similar adaptation works for the display of images with jsPsychImageButtonResponse.
Does not work:
var text_display = {
type: jsPsychHtmlButtonResponse,
stimulus: text_files/test.txt,
choices: ["Ready"],
};
Works:
var image_display = {
type: jsPsychImageButtonResponse,
stimulus: images_files/test.png,
choices: ["Ready"],
};
Do you have any suggestions how to handle this problem?
Text files behave differently from image files in this context. While browsers can load an image file directly from a path, text files need to be loaded using more generic methods. This question has answers that demonstrate how text files are loaded. You could use
fetch()to load in all the text files and assign them to variables that you then use in your experiment.Alternatively, if you want something that is as close as possible to this experience without getting into
fetch()calls, then you could put the text from your text file inside a JavaScript file and assign it to a variable.Suppose that this has the filename
test_txt.js. You can then load this in your HTML doc like you load other scripts (e.g., jspsych.js).Then you can use the
test_txtvariable in your code.