mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 16:48:12 +00:00
implements #148
This commit is contained in:
parent
3ef2f16f22
commit
9074c42e63
@ -18,8 +18,12 @@ incorrect_text | string | "Wrong." | String to show when the wrong answer is giv
|
|||||||
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).
|
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).
|
||||||
force_correct_button_press | boolean | false | If set to true, then the subject must press the correct response key after feedback is given in order to advance to the next trial.
|
force_correct_button_press | boolean | false | If set to true, then the subject must press the correct response key after feedback is given in order to advance to the next trial.
|
||||||
show_stim_with_feedback | boolean | true | If set to true, then the stimulus will be shown during feedback. If false, then only the text feedback will display during feedback.
|
show_stim_with_feedback | boolean | true | If set to true, then the stimulus will be shown during feedback. If false, then only the text feedback will display during feedback.
|
||||||
|
show_feedback_on_timeout | boolean | false | If true, then category feedback will be displayed for an incorrect response after a timeout (timing_response is exceeded). If false, then a timeout message will be shown.
|
||||||
|
timeout_message | string | "Please respond faster." | The message to show on a timeout non-response.
|
||||||
timing_stim | numeric | -1 | How long to show the stimulus for (milliseconds). If -1, then the stimulus is shown until a response is given.
|
timing_stim | numeric | -1 | How long to show the stimulus for (milliseconds). If -1, then the stimulus is shown until a response is given.
|
||||||
timing_feedback_duration | numeric | 2000 | How long to show the feedback for (milliseconds).
|
timing_feedback_duration | numeric | 2000 | How long to show the feedback for (milliseconds).
|
||||||
|
timing_response | numeric | -1 | The maximum time allowed for a response. If -1, then the experiment will wait indefinitely for a response.
|
||||||
|
|
||||||
|
|
||||||
## Data Generated
|
## Data Generated
|
||||||
|
|
||||||
|
@ -23,14 +23,16 @@
|
|||||||
trials[i].choices = params.choices;
|
trials[i].choices = params.choices;
|
||||||
trials[i].correct_text = (typeof params.correct_text === 'undefined') ? "<p class='feedback'>Correct</p>" : params.correct_text;
|
trials[i].correct_text = (typeof params.correct_text === 'undefined') ? "<p class='feedback'>Correct</p>" : params.correct_text;
|
||||||
trials[i].incorrect_text = (typeof params.incorrect_text === 'undefined') ? "<p class='feedback'>Incorrect</p>" : params.incorrect_text;
|
trials[i].incorrect_text = (typeof params.incorrect_text === 'undefined') ? "<p class='feedback'>Incorrect</p>" : params.incorrect_text;
|
||||||
// timing params
|
|
||||||
trials[i].timing_stim = params.timing_stim || -1; // default is to show image until response
|
|
||||||
trials[i].timing_feedback_duration = params.timing_feedback_duration || 2000;
|
|
||||||
// optional params
|
|
||||||
trials[i].show_stim_with_feedback = (typeof params.show_stim_with_feedback === 'undefined') ? true : params.show_stim_with_feedback;
|
trials[i].show_stim_with_feedback = (typeof params.show_stim_with_feedback === 'undefined') ? true : params.show_stim_with_feedback;
|
||||||
trials[i].is_html = (typeof params.is_html === 'undefined') ? false : params.is_html;
|
trials[i].is_html = (typeof params.is_html === 'undefined') ? false : params.is_html;
|
||||||
trials[i].force_correct_button_press = (typeof params.force_correct_button_press === 'undefined') ? false : params.force_correct_button_press;
|
trials[i].force_correct_button_press = (typeof params.force_correct_button_press === 'undefined') ? false : params.force_correct_button_press;
|
||||||
trials[i].prompt = (typeof params.prompt === 'undefined') ? '' : params.prompt;
|
trials[i].prompt = (typeof params.prompt === 'undefined') ? '' : params.prompt;
|
||||||
|
trials[i].show_feedback_on_timeout = (typeof params.show_feedback_on_timeout === 'undefined') ? false : params.show_feedback_on_timeout;
|
||||||
|
trials[i].timeout_message = params.timeout_message || "<p>Please respond faster.</p>";
|
||||||
|
// timing params
|
||||||
|
trials[i].timing_stim = params.timing_stim || -1; // default is to show image until response
|
||||||
|
trials[i].timing_response = params.timing_response || -1; // default is no max response time
|
||||||
|
trials[i].timing_feedback_duration = params.timing_feedback_duration || 2000;
|
||||||
}
|
}
|
||||||
return trials;
|
return trials;
|
||||||
};
|
};
|
||||||
@ -81,6 +83,9 @@
|
|||||||
clearTimeout(setTimeoutHandlers[i]);
|
clearTimeout(setTimeoutHandlers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clear keyboard listener
|
||||||
|
jsPsych.pluginAPI.cancelAllKeyboardResponses();
|
||||||
|
|
||||||
var correct = false;
|
var correct = false;
|
||||||
if (trial.key_answer == info.key) {
|
if (trial.key_answer == info.key) {
|
||||||
correct = true;
|
correct = true;
|
||||||
@ -98,7 +103,8 @@
|
|||||||
|
|
||||||
display_element.html('');
|
display_element.html('');
|
||||||
|
|
||||||
doFeedback(correct);
|
var timeout = info.rt == -1;
|
||||||
|
doFeedback(correct, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
jsPsych.pluginAPI.getKeyboardResponse({
|
jsPsych.pluginAPI.getKeyboardResponse({
|
||||||
@ -109,40 +115,48 @@
|
|||||||
allow_held_key: false
|
allow_held_key: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(trial.timing_response > 0) {
|
||||||
|
setTimeoutHandlers.push(setTimeout(function(){
|
||||||
|
after_response({key: -1, rt: -1});
|
||||||
|
}, trial.timing_response));
|
||||||
|
}
|
||||||
|
|
||||||
|
function doFeedback(correct, timeout) {
|
||||||
|
|
||||||
function doFeedback(correct) {
|
if(timeout && !trial.show_feedback_on_timeout){
|
||||||
// show image during feedback if flag is set
|
display_element.append(trial.timeout_message);
|
||||||
if (trial.show_stim_with_feedback) {
|
|
||||||
if (!trial.is_html) {
|
|
||||||
// add image to display
|
|
||||||
display_element.append($('<img>', {
|
|
||||||
"src": trial.a_path,
|
|
||||||
"class": 'jspsych-categorize-stimulus',
|
|
||||||
"id": 'jspsych-categorize-stimulus'
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
display_element.append($('<div>', {
|
|
||||||
"id": 'jspsych-categorize-stimulus',
|
|
||||||
"class": 'jspsych-categorize-stimulus',
|
|
||||||
"html": trial.a_path
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// substitute answer in feedback string.
|
|
||||||
var atext = "";
|
|
||||||
if (correct) {
|
|
||||||
atext = trial.correct_text.replace("%ANS%", trial.text_answer);
|
|
||||||
} else {
|
} else {
|
||||||
atext = trial.incorrect_text.replace("%ANS%", trial.text_answer);
|
// show image during feedback if flag is set
|
||||||
|
if (trial.show_stim_with_feedback) {
|
||||||
|
if (!trial.is_html) {
|
||||||
|
// add image to display
|
||||||
|
display_element.append($('<img>', {
|
||||||
|
"src": trial.a_path,
|
||||||
|
"class": 'jspsych-categorize-stimulus',
|
||||||
|
"id": 'jspsych-categorize-stimulus'
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
display_element.append($('<div>', {
|
||||||
|
"id": 'jspsych-categorize-stimulus',
|
||||||
|
"class": 'jspsych-categorize-stimulus',
|
||||||
|
"html": trial.a_path
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// substitute answer in feedback string.
|
||||||
|
var atext = "";
|
||||||
|
if (correct) {
|
||||||
|
atext = trial.correct_text.replace("%ANS%", trial.text_answer);
|
||||||
|
} else {
|
||||||
|
atext = trial.incorrect_text.replace("%ANS%", trial.text_answer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// show the feedback
|
||||||
|
display_element.append(atext);
|
||||||
}
|
}
|
||||||
|
|
||||||
// show the feedback
|
|
||||||
display_element.append(atext);
|
|
||||||
|
|
||||||
// check if force correct button press is set
|
// check if force correct button press is set
|
||||||
if (trial.force_correct_button_press && correct === false) {
|
if (trial.force_correct_button_press && correct === false && ((timeout && trial.show_feedback_on_timeout) || !timeout)) {
|
||||||
|
|
||||||
var after_forced_response = function(info) {
|
var after_forced_response = function(info) {
|
||||||
endTrial();
|
endTrial();
|
||||||
@ -150,7 +164,7 @@
|
|||||||
|
|
||||||
jsPsych.pluginAPI.getKeyboardResponse({
|
jsPsych.pluginAPI.getKeyboardResponse({
|
||||||
callback_function: after_forced_response,
|
callback_function: after_forced_response,
|
||||||
valid_responses: trial.key_answer,
|
valid_responses: [trial.key_answer],
|
||||||
rt_method: 'date',
|
rt_method: 'date',
|
||||||
persist: false,
|
persist: false,
|
||||||
allow_held_key: false
|
allow_held_key: false
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
correct_text: "<p class='center-content'>Correct. This face is %ANS%.</p>",
|
correct_text: "<p class='center-content'>Correct. This face is %ANS%.</p>",
|
||||||
incorrect_text: "<p class='center-content'>Incorrect. This face is %ANS%.</p>",
|
incorrect_text: "<p class='center-content'>Incorrect. This face is %ANS%.</p>",
|
||||||
prompt: "<p class='center-content'>Press H if the face is happy. Press S if the face is sad.</p>",
|
prompt: "<p class='center-content'>Press H if the face is happy. Press S if the face is sad.</p>",
|
||||||
|
timing_response: 1500,
|
||||||
|
show_feedback_on_timeout: false,
|
||||||
|
force_correct_button_press: true
|
||||||
};
|
};
|
||||||
|
|
||||||
function start(){
|
function start(){
|
||||||
|
Loading…
Reference in New Issue
Block a user