Word by word presentation plugin (based on the spr plugin) #1772
-
For an experiment I need to present sentences word by word. So basically, it should look like a SPR only that instead of space press showing the next word, the words should be presented after a set time (e.g. 450 ms). My idea was to adapt the spr plugin so that key press is not possible any more and instead trial duration ends the trial. Despite your excellent tutorial on plugins I still didn't get to the point where it works as expected (I admit I'm still a beginner with js and jspsych). So far, only the first word is presented for the trial duration and then the whole trial is finished without showing the other words. Probably, there is something I'm missing in regard of stimulus duration and trial duration. Maybe you could implement this word-by-word/wordwise plugin? Would be a great thing for many linguistic studies. Thanks a lot for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Hi @pcompen1, I agree that this is something others might be interested in. Do you mind sharing your current version of the plugin and a minimal example? If you provide something to start from, we should be able to help you get it working. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hey Becky, thanks so much! Well, as I said I'm still pretty new to jspsych and js in general. So I really just had some initial ideas what has to be changed but didn't really know how to do it. So an example could look like this, each word of the two trials should be presented one after another, exactly as in the spr trial just without button press. I also realized that this requires some changes with trial_duration and/or stimulus_duration (not sure if both are needed in this case):
For the plugin, I used Josh's spr-plugin as template but didn't really do much. Just deleted the key parameter and added trial_duration and stimulus_duration parameters. I also got rid of the reaction time stuff since we don't need to measure that and added ends if trial duration (but this is probably wrong, since the trial should end when all the words where presented and not when the trial_duration is reached). Sorry, I know that this script is a mess :D But I hope you can still see what I mean. Thanks so much!!
|
Beta Was this translation helpful? Give feedback.
-
Converting this to a discussion. |
Beta Was this translation helpful? Give feedback.
-
Here you go: jsPsych.plugins["word-by-word"] = (function() {
var plugin = {};
plugin.info = {
name: "word-by-word",
parameters: {
words: {
type: jsPsych.plugins.parameterType.STRING,
default: undefined
},
stimulus_duration: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'Stimulus duration',
default: null,
description: 'How long to hide the stimulus.'
}
}
}
plugin.trial = function(display_element, trial) {
// data saving
var trial_data = {
words: trial.words
};
var current_position = 0;
var n_words = trial.words.split(' ').length;
function create_moving_window(words, position){
var word_list = words.split(' ');
var stimulus = word_list.filter(function(word, index){
if(index == position){
return true;
}
});
return stimulus;
}
function show_stimulus(position){
display_element.innerHTML = "<p style='font-family: Arial; font-size: 32pt;'>" + create_moving_window(trial.words, position) + "</p>";
current_position++;
if(current_position == n_words){
end_trial();
} else {
jsPsych.pluginAPI.setTimeout(function() {
show_stimulus(current_position)
}, trial.stimulus_duration)
}
}
function end_trial(){
// clear the display
display_element.innerHTML = '';
// clear all timeouts
jsPsych.pluginAPI.clearAllTimeouts();
// end the trial and save the data
jsPsych.finishTrial(trial_data);
}
show_stimulus(current_position);
};
return plugin;
})(); Here's what I did:
I hope this helps! Let us know if you have any problems or further questions. |
Beta Was this translation helpful? Give feedback.
Here you go: