Merge pull request #167 from vergenzt/same-different-self-pacing

Improvements to same-different plugin
This commit is contained in:
Josh de Leeuw 2015-12-08 16:44:25 -05:00
commit 82ce051210
2 changed files with 29 additions and 9 deletions

View File

@ -13,7 +13,7 @@ is_html | boolean | false | If the elements of the `stimuli` array are strings c
answer | array | *undefined* | Array of strings, where each string is either `'same'` or `'different'`. This array should be the same length as `stimuli` and the answers should correspond to the pairs in the `stimuli` array.
same_key | numeric or string | 'Q' | The key that subjects should press to indicate that the two stimuli are the same.
different_key | numeric or string | 'P' | The key that subjects should press to indicate that the two stimuli are different.
timing_first_stim | numeric | 1000 | How long to show the first stimulus for in milliseconds.
timing_first_stim | numeric | 1000 | How long to show the first stimulus for in milliseconds. If the value of this parameter is `-1` then the stimulus will be shown until the subject presses any key.
timing_gap | numeric | 500 | How long to show a blank screen in between the two stimuli.
timing_second_stim | numeric | 1000 | How long to show the second stimulus for in milliseconds. If the value of this parameter is `-1` then the stimulus will be shown until the subject responds.
prompt | string | "" | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g. which key to press).
@ -25,11 +25,18 @@ In addition to the [default data collected by all plugins](overview#datacollecte
Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw first on this trial.
stimulus_2 | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw second on this trial.
stimulus | string | An array of length 2 containing either the path to the image file or the string containing the HTML formatted content that the subject saw for each trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the second stimulus first appears on the screen until the subject's response.
correct | boolean | `true` if the subject's response matched the `answer` for this trial.
answer | string | The correct answer to the trial, either `'same'` or `'different'`.
Additionally, if `timing_first_stim` is `-1`, then the following data is also collected:
Name | Type | Value
-----|------|------
rt_stim1 | numeric | The response time in milliseconds for the subject to continue after the first stimulus. The time is measured from when the first stimulus appears on the screen until the subject's response.
key_press_stim1 | numeric | Indicates which key the subject pressed to continue. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
## Examples

View File

@ -24,7 +24,7 @@
trials[i].same_key = params.same_key || 81; // default is 'q'
trials[i].different_key = params.different_key || 80; // default is 'p'
// timing parameters
trials[i].timing_first_stim = params.timing_first_stim || 1000;
trials[i].timing_first_stim = params.timing_first_stim || 1000; // if -1, the first stim is shown until any key is pressed
trials[i].timing_second_stim = params.timing_second_stim || 1000; // if -1, then second stim is shown until response.
trials[i].timing_gap = params.timing_gap || 500;
// optional parameters
@ -62,11 +62,19 @@
}));
}
// remove image after duration
setTimeoutHandlers.push(setTimeout(function() {
showBlankScreen();
}, trial.timing_first_stim));
var first_stim_info;
if (trial.timing_first_stim > 0) {
setTimeoutHandlers.push(setTimeout(function() {
showBlankScreen();
}, trial.timing_first_stim));
}
else {
function afterKeyboardResponse(info) {
first_stim_info = info;
showBlankScreen();
}
jsPsych.pluginAPI.getKeyboardResponse(afterKeyboardResponse, [], 'date', false);
}
function showBlankScreen() {
$('.jspsych-same-different-stimulus').remove();
@ -121,10 +129,15 @@
var trial_data = {
"rt": info.rt,
"answer": trial.answer,
"correct": correct,
"stimulus": JSON.stringify([trial.a_path, trial.b_path]),
"key_press": info.key
};
if (first_stim_info) {
trial_data["rt_stim1"] = first_stim_info.rt;
trial_data["key_press_stim1"] = first_stim_info.key;
}
jsPsych.data.write(trial_data);
display_element.html('');