jsPsych/examples/timeline-variables.html
2024-06-27 14:58:35 -04:00

90 lines
2.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<script src="../packages/jspsych/dist/index.browser.js"></script>
<script src="../packages/plugin-html-keyboard-response/dist/index.browser.js"></script>
<script src="../packages/plugin-image-keyboard-response/dist/index.browser.js"></script>
<script src="../packages/plugin-preload/dist/index.browser.js"></script>
<script src="../packages/metadata/dist/index.browser.js"></script>
<link rel="stylesheet" href="../packages/jspsych/css/jspsych.css">
</head>
<body></body>
<script>
const metadata_options = {
randomField: "this is a field",
author: {
"John": {
name: "John",
givenName: "Johnathan",
},
},
variables: {
"trial_type" : {
description: {
"chat-plugin": "this chat plugin allows you to talk to gpt!",
}
},
"trial_index": {
name: "index",
},
},
}
var jsPsych = initJsPsych({
on_finish: async function() {
await metadata.generate(jsPsych.data.get().json());
// await metadata.generate(jsPsych.data.get().csv(), metadata_options, true);
// metadata.saveAsJsonFile();
jsPsych.data.displayData();
metadata.displayMetadata(jsPsych.getDisplayElement());
},
default_iti: 250
});
var metadata = new jsPsychMetadata(); // could declare with jsPsych to show the after
// manually preload the image files, since they are passed to the image-keyboard-response stimulus parameter
// through timeline variables, and therefore cannot be automatically preloaded
var images = ['img/happy_face_1.jpg', 'img/happy_face_2.jpg', 'img/happy_face_3.jpg'];
var preload = {
type: jsPsychPreload,
images: images
};
var timeline_variables = [
{ v1: 'img/happy_face_1.jpg', v2: 'Ann' },
{ v1: 'img/happy_face_2.jpg', v2: 'Jackson' },
{ v1: 'img/happy_face_3.jpg', v2: 'Riley' }
];
var node = {
timeline_variables: timeline_variables,
timeline: [
{
type: jsPsychHtmlKeyboardResponse,
choices: "NO_KEYS",
stimulus: "<p style='text-align:center; font-size:80px;'>+</p>",
trial_duration: 500,
},
{
type: jsPsychImageKeyboardResponse,
choices: ['y','n'],
stimulus: jsPsych.timelineVariable('v1'),
prompt: function() {
return '<p>Have you seen '+jsPsych.timelineVariable('v2', true)+ ' before? Press "y" or "n".</p>'
},
stimulus_width: 300
}
],
randomize_order: true,
repetitions: 2
};
jsPsych.run([preload, node]);
</script>
</html>