I am trying out the tutorial how to use jsPsych
on pavlovia (see Pavlovia). However, I am not able to load the plugins suggested by that page.
This links also returns a 404 error:
https://run.pavlovia.org/jaquent/jspsych_test/lib/vendors/jspsych-7.3.1/plugins/jspsych-html-keyboard-response.js
While a much older version can be loaded:
https://run.pavlovia.org/jaquent/jspsych_test/lib/vendors/jspsych-6.0.0/plugins/jspsych-html-keyboard-response.js
Could someone advise me which is the latest version of jsPsych
that I can use how do I access that.
The code
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<script type="text/javascript" src="lib/vendors/jspsych-7.1.2/jspsych.js"></script>
<link rel="stylesheet" type="text/css" href="lib/vendors/jspsych-7.3.4/css/jspsych.css"/>
<script type="text/javascript" src="lib/vendors/jspsych-7.1.2/plugins/jspsych-html-keyboard-response.js"></script>
<script type="text/javascript" src="lib/vendors/jspsych-7.1.2/plugins/jspsych-image-keyboard-response.js"></script>
<script type="text/javascript" src="lib/vendors/jspsych-7.1.2/plugin-preload.js"></script>
<script type="text/javascript" src="lib/jspsych-7-pavlovia-2022.1.1.js"></script>
</head>
<body></body>
<script>
/* initialize jsPsych */
var jsPsych = initJsPsych({
override_safe_mode: false,
on_finish: function() {
jsPsych.data.displayData();
}
});
/* create timeline */
var timeline = [];
/* init connection with pavlovia.org */
var pavlovia_init = {
type: "pavlovia",
command: "init"
};
timeline.push(pavlovia_init);
/* preload images */
var preload = {
type: jsPsychPreload,
images: ['img/blue.png', 'img/orange.png']
};
timeline.push(preload);
/* define welcome message trial */
var welcome = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "Welcome to the experiment. Press any key to begin."
};
timeline.push(welcome);
/* define instructions trial */
var instructions = {
type: jsPsychHtmlKeyboardResponse,
stimulus: `
<p>In this experiment, a circle will appear in the center
of the screen.</p><p>If the circle is <strong>blue</strong>,
press the letter F on the keyboard as fast as you can.</p>
<p>If the circle is <strong>orange</strong>, press the letter J
as fast as you can.</p>
<div style='width: 700px;'>
<div style='float: left;'><img src='img/blue.png'></img>
<p class='small'><strong>Press the F key</strong></p></div>
<div style='float: right;'><img src='img/orange.png'></img>
<p class='small'><strong>Press the J key</strong></p></div>
</div>
<p>Press any key to begin.</p>
`,
post_trial_gap: 2000
};
timeline.push(instructions);
/* define trial stimuli array for timeline variables */
var test_stimuli = [
{ stimulus: "img/blue.png", correct_response: 'f'},
{ stimulus: "img/orange.png", correct_response: 'j'}
];
/* define fixation and test trials */
var fixation = {
type: jsPsychHtmlKeyboardResponse,
stimulus: '<div style="font-size:60px;">+</div>',
choices: "NO_KEYS",
trial_duration: function(){
return jsPsych.randomization.sampleWithoutReplacement([250, 500, 750, 1000, 1250, 1500, 1750, 2000], 1)[0];
},
data: {
task: 'fixation'
}
};
var test = {
type: jsPsychImageKeyboardResponse,
stimulus: jsPsych.timelineVariable('stimulus'),
choices: ['f', 'j'],
data: {
task: 'response',
correct_response: jsPsych.timelineVariable('correct_response')
},
on_finish: function(data){
data.correct = jsPsych.pluginAPI.compareKeys(data.response, data.correct_response);
}
};
/* define test procedure */
var test_procedure = {
timeline: [fixation, test],
timeline_variables: test_stimuli,
repetitions: 5,
randomize_order: true
};
timeline.push(test_procedure);
/* define debrief */
var debrief_block = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function() {
var trials = jsPsych.data.get().filter({task: 'response'});
var correct_trials = trials.filter({correct: true});
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
var rt = Math.round(correct_trials.select('rt').mean());
return `<p>You responded correctly on ${accuracy}% of the trials.</p>
<p>Your average response time was ${rt}ms.</p>
<p>Press any key to complete the experiment. Thank you!</p>`;
}
};
timeline.push(debrief_block);
/* finish connection with pavlovia.org */
var pavlovia_finish = {
type: "pavlovia",
command: "finish"
};
timeline.push(pavlovia_finish);
/* start the experiment */
jsPsych.run(timeline);
</script>
</html>