diff --git a/docs/markdown_docs/core_library/jspsych-core.md b/docs/markdown_docs/core_library/jspsych-core.md index b7c70631..161b4250 100644 --- a/docs/markdown_docs/core_library/jspsych-core.md +++ b/docs/markdown_docs/core_library/jspsych-core.md @@ -22,8 +22,6 @@ Adds the timeline to the end of the experiment. ### Example -#### End the experiment if a particular response is given - ```javascript var trial = { type: 'text', @@ -350,6 +348,41 @@ var settings = jsPsych.initSettings(); console.log(JSON.stringify(settings.timeline)); ``` +--- +## jsPsych.pauseExperiment +``` +jsPsych.pauseExperiment() +``` + +### Parameters + +None. + +### Return value + +None. + +### Description + +Pauses the experiment. The experiment will finish the current trial, but will not execute any additional trials until `jsPsych.resumeExperiment()` is called. + +### Example + +```javascript +var trial = { + type: 'single-stim', + stimulus: 'Press p to take a 30 second break. Otherwise, press c to continue immediately.', + is_html: true, + choices: ['p','c'], + on_finish: function(data){ + if(data.key_press == 80) { // 80 = p + jsPsych.pauseExperiment(); + setTimeout(jsPsych.resumeExperiment, 30000); + } + } +} +``` + --- ## jsPsych.progress @@ -385,6 +418,41 @@ var progress = jsPsych.progress(); alert('You have completed approximately '+progress.percent_complete+'% of the experiment'); ``` +--- +## jsPsych.resumeExperiment +``` +jsPsych.resumeExperiment() +``` + +### Parameters + +None. + +### Return value + +None. + +### Description + +Resumes the experiment after a call to `jsPsych.pauseExperiment()`. If the post trial delay (`timing_post_trial`) has not yet been reached, then the experiment will not continue until the delay is finished. For example, if `timing_post_trial` was 10,000ms and `jsPsych.resumeExperiment()` was called 6,000ms after the previous trial finished, then the experiment would not continue for another 4,000ms. + +### Example + +```javascript +var trial = { + type: 'single-stim', + stimulus: 'Press p to take a 30 second break. Otherwise, press c to continue immediately.', + is_html: true, + choices: ['p','c'], + on_finish: function(data){ + if(data.key_press == 80) { // 80 = p + jsPsych.pauseExperiment(); + setTimeout(jsPsych.resumeExperiment, 30000); + } + } +} +``` + --- ## jsPsych.startTime diff --git a/docs/markdown_docs/core_library/overview.md b/docs/markdown_docs/core_library/overview.md index e328a50c..bbd92b95 100644 --- a/docs/markdown_docs/core_library/overview.md +++ b/docs/markdown_docs/core_library/overview.md @@ -14,8 +14,10 @@ Every jsPsych experiment utilizes the core library (contained in the `jspsych.js * [jsPsych.finishTrial](jspsych-core.md#jspsychfinishtrial) * [jsPsych.getDisplayElement](jspsych-core.md#jspsychgetdisplayelement) * [jsPsych.init](jspsych-core.md#jspsychinit) -* [jsPsych.initSettings](jspsych-core.md#jspsychinitSettings) +* [jsPsych.initSettings](jspsych-core.md#jspsychinitsettings) +* [jsPsych.pauseExperiment](jspsych-core.md#jspsychpauseexperiment) * [jsPsych.progress](jspsych-core.md#jspsychprogress) +* [jsPsych.resumeExperiment](jspsych-core.md#jspsychresumeexperiment) * [jsPsych.startTime](jspsych-core.md#jspsychstarttime) * [jsPsych.totalTime](jspsych-core.md#jspsychtotaltime)