mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
Add response_ends_trial parameter to VisualSearchCirclePlugin
This commit is contained in:
parent
d33176a5f3
commit
d54048b8d0
@ -89,6 +89,12 @@ const info = <const>{
|
|||||||
pretty_name: "Fixation duration",
|
pretty_name: "Fixation duration",
|
||||||
default: 1000,
|
default: 1000,
|
||||||
},
|
},
|
||||||
|
/** Whether a keyboard response ends the trial early */
|
||||||
|
response_ends_trial: {
|
||||||
|
type: ParameterType.BOOL,
|
||||||
|
pretty_name: "Response ends trial",
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -153,12 +159,21 @@ class VisualSearchCirclePlugin implements JsPsychPlugin<Info> {
|
|||||||
}, trial.fixation_duration);
|
}, trial.fixation_duration);
|
||||||
};
|
};
|
||||||
|
|
||||||
const end_trial = (rt: number, correct: boolean, key_press: string) => {
|
const response = {
|
||||||
|
rt: null,
|
||||||
|
key: null,
|
||||||
|
correct: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
const end_trial = () => {
|
||||||
|
this.jsPsych.pluginAPI.clearAllTimeouts();
|
||||||
|
this.jsPsych.pluginAPI.cancelAllKeyboardResponses();
|
||||||
|
|
||||||
// data saving
|
// data saving
|
||||||
var trial_data = {
|
const trial_data = {
|
||||||
correct: correct,
|
correct: response.correct,
|
||||||
rt: rt,
|
rt: response.rt,
|
||||||
response: key_press,
|
response: response.key,
|
||||||
locations: display_locs,
|
locations: display_locs,
|
||||||
target_present: trial.target_present,
|
target_present: trial.target_present,
|
||||||
set_size: trial.set_size,
|
set_size: trial.set_size,
|
||||||
@ -186,11 +201,7 @@ class VisualSearchCirclePlugin implements JsPsychPlugin<Info> {
|
|||||||
"px;'></img>";
|
"px;'></img>";
|
||||||
}
|
}
|
||||||
|
|
||||||
var trial_over = false;
|
|
||||||
|
|
||||||
const after_response = (info: { key: string; rt: number }) => {
|
const after_response = (info: { key: string; rt: number }) => {
|
||||||
trial_over = true;
|
|
||||||
|
|
||||||
var correct = false;
|
var correct = false;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -202,12 +213,16 @@ class VisualSearchCirclePlugin implements JsPsychPlugin<Info> {
|
|||||||
correct = true;
|
correct = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_display();
|
response.rt = info.rt;
|
||||||
|
response.key = info.key;
|
||||||
|
response.correct = correct;
|
||||||
|
|
||||||
end_trial(info.rt, correct, info.key);
|
if (trial.response_ends_trial) {
|
||||||
|
end_trial();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var valid_keys = [trial.target_present_key, trial.target_absent_key];
|
const valid_keys = [trial.target_present_key, trial.target_absent_key];
|
||||||
|
|
||||||
const key_listener = this.jsPsych.pluginAPI.getKeyboardResponse({
|
const key_listener = this.jsPsych.pluginAPI.getKeyboardResponse({
|
||||||
callback_function: after_response,
|
callback_function: after_response,
|
||||||
@ -219,19 +234,11 @@ class VisualSearchCirclePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(() => {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
if (!trial_over) {
|
if (!response.rt) {
|
||||||
this.jsPsych.pluginAPI.cancelKeyboardResponse(key_listener);
|
this.jsPsych.pluginAPI.cancelKeyboardResponse(key_listener);
|
||||||
|
|
||||||
trial_over = true;
|
|
||||||
|
|
||||||
var rt = null;
|
|
||||||
var correct = false;
|
|
||||||
var key_press = null;
|
|
||||||
|
|
||||||
clear_display();
|
|
||||||
|
|
||||||
end_trial(rt, correct, key_press);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end_trial();
|
||||||
}, trial.trial_duration);
|
}, trial.trial_duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user