Demo flanker working ++ updates to keyboard-response simulate methods ++ added remove_post_trial_gap to simluate_opts

This commit is contained in:
nikbpetrov 2021-06-07 23:45:36 +01:00
parent 8dc1959d13
commit 3dbcd94ef0
4 changed files with 26 additions and 4 deletions

View File

@ -111,6 +111,13 @@
timeline: timeline, timeline: timeline,
on_finish: function() { on_finish: function() {
jsPsych.data.displayData(); jsPsych.data.displayData();
},
simulate: true,
// will need to handle what happens when only partially defined
simulate_opts: {
'trial_duration': 25,
'response_ends_trial': true,
'remove_post_trial_gap': true
} }
}); });
</script> </script>

View File

@ -104,7 +104,8 @@ window.jsPsych = (function() {
'simulate': false, 'simulate': false,
'simulate_opts': { 'simulate_opts': {
'trial_duration': 500, 'trial_duration': 500,
'response_ends_trial': true 'response_ends_trial': true,
'remove_post_trial_gap': true
} }
}; };
@ -1031,6 +1032,9 @@ window.jsPsych = (function() {
if (trial.response_ends_trial !== true) { if (trial.response_ends_trial !== true) {
trial.response_ends_trial = true trial.response_ends_trial = true
} }
if (curr_trial_opts.remove_post_trial_gap === true) {
trial.post_trial_gap = 0
}
} }

View File

@ -147,7 +147,13 @@ jsPsych.plugins["html-keyboard-response"] = (function() {
plugin.simulate = function(trial, simulate_opts) { plugin.simulate = function(trial, simulate_opts) {
if(trial.choices !== jsPsych.NO_KEYS) { if(trial.choices !== jsPsych.NO_KEYS) {
var key_response = jsPsych.randomization.sampleWithoutReplacement(trial.choices, 1)[0]; let valid_keys
if (trial.choices === jsPsych.ALL_KEYS) {
valid_keys = ['enter', 'space', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
} else {
valid_keys = trial.choices
}
var key_response = jsPsych.randomization.sampleWithoutReplacement(valid_keys, 1)[0];
setTimeout(function(){ setTimeout(function(){
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {key: key_response})); document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {key: key_response}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {key: key_response})); document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {key: key_response}));

View File

@ -260,9 +260,14 @@ jsPsych.plugins["image-keyboard-response"] = (function() {
}; };
plugin.simulate = function(trial, simulate_opts) { plugin.simulate = function(trial, simulate_opts) {
console.log('vleze')
if(trial.choices !== jsPsych.NO_KEYS) { if(trial.choices !== jsPsych.NO_KEYS) {
var key_response = jsPsych.randomization.sampleWithoutReplacement(trial.choices, 1)[0]; let valid_keys
if (trial.choices === jsPsych.ALL_KEYS) {
valid_keys = ['enter', 'space', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
} else {
valid_keys = trial.choices
}
var key_response = jsPsych.randomization.sampleWithoutReplacement(valid_keys, 1)[0];
setTimeout(function(){ setTimeout(function(){
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {key: key_response})); document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {key: key_response}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {key: key_response})); document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {key: key_response}));