Skip to content

Commit

Permalink
add documentation for abortTimelineByName
Browse files Browse the repository at this point in the history
  • Loading branch information
jodeleeuw committed Nov 9, 2023
1 parent 978a4c8 commit a4c573e
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions docs/reference/jspsych.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,74 @@ var trial = {
}
```

---
## jsPsych.abortTimelineByName

```javascript
jsPsych.abortTimelineByName()
```

### Parameters

| Parameter | Type | Description |
| --------------- | -------- | ---------------------------------------- |
| name | string | The name of the timeline to abort. |

### Return value

None.

### Description

Ends the currently active timeline that matches the `name` parameter. This can be used to control which level is aborted in a nested timeline structure.

### Example

#### Abort a procedure if an incorrect response is given.

```javascript
const fixation = {
type: jsPsychHtmlKeyboardResponse,
stimulus: '<p>+</p>',
choices: "NO_KEYS",
trial_duration: 1000
}

const test = {
type: jsPsychImageKeyboardResponse,
stimulus: jsPsych.timelineVariable('stimulus'),
choices: ['y', 'n'],
on_finish: function(data){
if(jsPsych.pluginAPI.compareKeys(data.response, "n")){
jsPsych.abortTimelineByName('memory_test');
}
}
}

const memoryResponseProcedure = {
timeline: [fixation, test]
}

// the variable `encode` is not shown, but imagine a trial that displays
// some stimulus to remember.
const memoryEncodeProcedure = {
timeline: [fixation, encode]
}

const memoryTestProcedure = {
timeline: [memoryEncodeProcedure, memoryResponseProcedure]
name: 'memory_test',
timeline_variables: [
{stimulus: 'image1.png'},
{stimulus: 'image2.png'},
{stimulus: 'image3.png'},
{stimulus: 'image4.png'}
]
}


```

---
## jsPsych.addNodeToEndOfTimeline

Expand Down

0 comments on commit a4c573e

Please sign in to comment.