From d54048b8d09964c4d248ad3ff2c152a6c4ca5a2c Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Sun, 14 Jan 2024 12:51:34 -0500 Subject: [PATCH 1/4] Add response_ends_trial parameter to VisualSearchCirclePlugin --- .../plugin-visual-search-circle/src/index.ts | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/packages/plugin-visual-search-circle/src/index.ts b/packages/plugin-visual-search-circle/src/index.ts index 1232970d03..0efff05000 100644 --- a/packages/plugin-visual-search-circle/src/index.ts +++ b/packages/plugin-visual-search-circle/src/index.ts @@ -89,6 +89,12 @@ const info = { pretty_name: "Fixation duration", 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 { }, 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 - var trial_data = { - correct: correct, - rt: rt, - response: key_press, + const trial_data = { + correct: response.correct, + rt: response.rt, + response: response.key, locations: display_locs, target_present: trial.target_present, set_size: trial.set_size, @@ -186,11 +201,7 @@ class VisualSearchCirclePlugin implements JsPsychPlugin { "px;'>"; } - var trial_over = false; - const after_response = (info: { key: string; rt: number }) => { - trial_over = true; - var correct = false; if ( @@ -202,12 +213,16 @@ class VisualSearchCirclePlugin implements JsPsychPlugin { 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({ callback_function: after_response, @@ -219,19 +234,11 @@ class VisualSearchCirclePlugin implements JsPsychPlugin { if (trial.trial_duration !== null) { this.jsPsych.pluginAPI.setTimeout(() => { - if (!trial_over) { + if (!response.rt) { 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); } From 1c7d0af829a05f93d2e70244447eba9c2289c955 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Sun, 14 Jan 2024 12:54:35 -0500 Subject: [PATCH 2/4] add test case for response_ends_trial --- .../src/index.spec.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/plugin-visual-search-circle/src/index.spec.ts b/packages/plugin-visual-search-circle/src/index.spec.ts index c2008b3388..bb69740c75 100644 --- a/packages/plugin-visual-search-circle/src/index.spec.ts +++ b/packages/plugin-visual-search-circle/src/index.spec.ts @@ -29,6 +29,36 @@ describe("visual-search-circle", () => { expect(getData().values()[0].correct).toBe(true); }); + + it("wait when response_ends_trial is false", async () => { + const { displayElement, expectFinished, expectRunning, getData } = await startTimeline([ + { + type: visualSearchCircle, + target: "target.png", + foil: "foil.png", + fixation_image: "fixation.png", + set_size: 4, + target_present: true, + target_present_key: "a", + target_absent_key: "b", + response_ends_trial: false, + trial_duration: 1500, + }, + ]); + + expect(displayElement.querySelectorAll("img").length).toBe(1); + + jest.advanceTimersByTime(1000); // fixation duration + + expect(displayElement.querySelectorAll("img").length).toBe(5); + pressKey("a"); + await expectRunning(); + + jest.runAllTimers(); + await expectFinished(); + + expect(getData().values()[0].correct).toBe(true); + }); }); describe("visual-search-circle simulation", () => { From 37430e13e9645d90e853471010bee0c95c895954 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Sun, 14 Jan 2024 12:56:38 -0500 Subject: [PATCH 3/4] add changeset --- .changeset/strong-ligers-join.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/strong-ligers-join.md diff --git a/.changeset/strong-ligers-join.md b/.changeset/strong-ligers-join.md new file mode 100644 index 0000000000..fa12b2d1c8 --- /dev/null +++ b/.changeset/strong-ligers-join.md @@ -0,0 +1,5 @@ +--- +"@jspsych/plugin-visual-search-circle": minor +--- + +Adds response_ends_trial parameter, with a default value of `true` From ba39cca0da722b55d49931e06401e83829d35dfe Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Sun, 14 Jan 2024 12:56:52 -0500 Subject: [PATCH 4/4] add documentation update --- docs/plugins/visual-search-circle.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/plugins/visual-search-circle.md b/docs/plugins/visual-search-circle.md index f17c8c825e..b41ac8facb 100644 --- a/docs/plugins/visual-search-circle.md +++ b/docs/plugins/visual-search-circle.md @@ -32,6 +32,7 @@ The `target_present` and `fixation_image` parameters must always be specified. O | target_absent_key | string | 'f' | The key to press if the target is not present in the search array. | | trial_duration | numeric | null | The maximum amount of time the participant is allowed to search before the trial will continue. A value of null will allow the participant to search indefinitely. | | fixation_duration | numeric | 1000 | How long to show the fixation image for before the search array (in milliseconds). | +| response_ends_trial| boolean | true | If true, the trial will end when the participant makes a response. | ## Data Generated