add parametertype and build environment docs

This commit is contained in:
jade 2024-11-07 17:12:54 -05:00
parent 0fc1bf0e6c
commit 36f75cc46a

View File

@ -61,6 +61,10 @@ const info = {
}
```
??? info "Custom Build Environments"
If you are using a custom build environment that imports its own `tsconfig.json` file that does not extend jsPsych's, but you want to use this syntax, you must add `"resolveJsonModule": true` to the config's `compilerOptions` object.
If you are not using a build environment that supports `import` and `package.json` (such as writing a plain JS file), you can manually enter the `version` as a string.
```javascript
@ -163,6 +167,106 @@ class MyAwesomePlugin {
MyAwesomePlugin.info = info;
```
#### Parameter Types
jsPsych currently has support for the following parameters:
| Type Name | Description | Example |
| --------- | ----------- | ------- |
| BOOL | A simple truth value. | `true` or `false` |
| STRING | A set of characters. | "Continue" |
| INT | A value that supports whole numbers. | 12 |
| FLOAT | A value that supports decimal numbers. | 5.55 |
| FUNCTION | A Javascript function, tends to process multiple objects in an array from other parameters. | `function(tries) { return "<p>You have " + tries + " tries left." }` |
| KEY | A single key, with support for function keys like arrows and spacebars. | `"j"`, `"n"`, `"ArrowLeft"` |
| KEYS | Either an array of keys, or the string `"ALL_KEYS"` or `"NO_KEYS"`, indicating their respective inclusion/exclusion criterea. | `["f", "j"]` |
| SELECT | A list of strings that a developer can choose between as a parameter. | `["cm", "px", "em"]` |
| HTML_STRING | A string with HTML markup. | `"<p>This is the prompt.</p>"` |
| IMAGE | A string that contains the path to an image file. | `"my_image.jpg"` |
| AUDIO | A string that contains the path to an audio file. | `"my_sound.mp3"` |
| VIDEO | A string that contains the path to a video file. | `"my_video.mp4"` |
| OBJECT | A general JSON object (key-value pairs). | `{ rt: 350, response: "hello!", correct: true }` |
| COMPLEX | A JSON object that one can specify nested parameters for. | `{ rt: 350, response: "hello!", correct: true }` |
| TIMELINE | A jsPsych timeline object with trials. | `[{ type: jsPsychKeyboardResponse, stimulus: 'my_image.jpg }]` |
Within each parameter, you may also specify if it is an array of the specific type. For example, a parameter that requires a list of button labels would be described as:
```js
const info = {
// ...
parameters: {
/** The labels to be displayed on each button. */
labels: {
type: ParameterType.STRING,
array: true,
default: ["Pause", "Play", "Continue"]
}
},
// ...
}
```
Specific parameter types also have their own special markup. For `ParameterType.SELECT`, you specify the options one can choose with an `options` field, and then the `default` field must be within that field.
```js
const info = {
// ...
parameters: {
/** The units of measure used to display the length and width of the stimulus. */
units: {
type: ParameterType.SELECT,
options: ["em", "px", "vh", "vw"],
default: "px"
}
},
// ...
}
```
For `ParameterType.COMPLEX`, we may specify the underlying fields in the object with the `nested` field. This acts in the same way as us defining parameters regularly, only we are now just delineating the fields within the object itself.
```js
const info = {
// ...
parameters: {
/** Where to display the location of the stimuli. */
locations: {
type: ParameterType.COMPLEX,
array: true,
default: undefined,
nested: {
/** The x-coordinate of the stimulus, in the units from the `units` field. */
x: {
type: ParameterType.INT
},
/** The y-coordinate of the stimulus. */
y: {
type: ParameterType.INT
}
}
}
},
// ...
}
```
For more complicated scenarios, typically when handling data generated from an arbitrary function or user input, where we have a general idea of what data type it could produce, we may also specify multiple types of data. As an example, if we know we'll get either some number (integer or float) or a string from a field, we can specify it as such:
```js
const info = {
// ...
data: {
/** The response given by the user. */
response: {
type:
ParameterType.INT |
ParameterType.FLOAT |
ParameterType.STRING
}
}
}
```
## Plugin functionality
Inside the `.trial()` method you can do pretty much anything that you want, including modifying the DOM, setting up event listeners, and making asynchronous requests. In this section we'll highlight a few common things that you might want to do as examples.