mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-11 16:18:11 +00:00
change RDK correct_choice parameter to only allow array of strings (not a single string)
This commit is contained in:
parent
2319a9a211
commit
d731518112
@ -33,7 +33,7 @@
|
||||
var trial = {
|
||||
type: "rdk",
|
||||
coherent_direction: 0,
|
||||
correct_choice: "p"
|
||||
correct_choice: ["p"]
|
||||
};
|
||||
|
||||
var trial_loop = {
|
||||
|
@ -36,7 +36,7 @@
|
||||
number_of_dots: 200,
|
||||
RDK_type: 3,
|
||||
choices: ["a", "l"],
|
||||
correct_choice: "a",
|
||||
correct_choice: ["a"],
|
||||
coherent_direction: 180,
|
||||
trial_duration: 1000
|
||||
};
|
||||
|
@ -34,7 +34,7 @@
|
||||
type: "rdk",
|
||||
number_of_apertures: 3, //This needs to be set if more than one aperture
|
||||
trial_duration: 10000,
|
||||
correct_choice: "a",
|
||||
correct_choice: ["a"],
|
||||
RDK_type: 3, //Applied to all apertures if only one value
|
||||
aperture_width: 200, //Applied to all apertures if only one value
|
||||
number_of_dots: [50, 200, 100], //Different parameter for each aperture. Array length must equal number_of_apertures
|
||||
|
@ -16,7 +16,7 @@ In addition to the [parameters available in all plugins](/overview/plugins#param
|
||||
| Parameter | Type | Default Value | Descripton |
|
||||
| ------------------------ | ---------------- | -------------------- | ---------------------------------------- |
|
||||
| choices | array of strings | jsPsych.ALL_KEYS | The valid keys that the subject can press as a response. Must be an array of strings. If left unspecified, any key is a valid key. |
|
||||
| correct_choice | array or string | *undefined* | The keys that are considered the correct response for that particular trial. Can be a single string or an array of strings. This needs to be linked with the `coherent_direction` parameter (see Examples section below for an illustration). This is used to determine whether the subject chose the correct response. The boolean indicating whether or not the subject chose the correct response is returned in the `correct` key of the data object. |
|
||||
| correct_choice | array of strings | *undefined* | Array containing the key(s) that are considered the correct response for that particular trial. This needs to be linked with the `coherent_direction` parameter (see Examples section below for an illustration). This is used to determine whether the subject chose the correct response. The boolean indicating whether or not the subject chose the correct response is returned in the `correct` key of the data object. |
|
||||
| trial_duration | numeric | 500 | The amount of time that the stimulus is displayed on the screen in ms. If -1, the stimulus will be displayed until the subject keys in a valid response. (`choices` parameter must contain valid keys or else the stimuli will run indefinitely). |
|
||||
| response_ends_trial | boolean | true | If `true`, then the subject's response will end the trial. If `false`, the stimuli will be presented for the full `trial_duration` (the response will be recorded as long as the subject responds within the trial duration). |
|
||||
| number_of_apertures | numeric | 1 | The number of apertures or RDKs on the screen. If set to more than one, remember to set the location (i.e., aperture_center_x and aperture_center_y) parameters to separate them. <br>In addition, each aperture can be customized individually by passing in an array of values as the parameter (see example below). If a single value (not an array) is passed as the parameter, then all apertures will have the same parameter. |
|
||||
@ -67,7 +67,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
| ---------------- | ----------- | ---------------------------------------- |
|
||||
| rt | numeric | The response time in ms for the subject to make a response. |
|
||||
| response | string | The key that the subject pressed. |
|
||||
| correct | boolean | Whether or not the subject's key press corresponded to those provided in correct_choice. |
|
||||
| correct | boolean | Whether or not the subject's key press matches any of the key(s) provided in correct_choice. |
|
||||
| frame_rate | numeric | The average frame rate for the trial. 0 denotes that the subject responded before the appearance of the second frame. |
|
||||
| number_of_frames | numeric | The number of frames that was shown in this trial. |
|
||||
| frame_rate_array | array | The array that holds the number of miliseconds for each frame in this trial. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
|
||||
@ -82,7 +82,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
var trial = {
|
||||
type: "rdk",
|
||||
coherent_direction: 0,
|
||||
correct_choice: "p"
|
||||
correct_choice: ["p"]
|
||||
};
|
||||
```
|
||||
=== "Demo"
|
||||
@ -99,7 +99,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
number_of_dots: 200,
|
||||
RDK_type: 3,
|
||||
choices: ["a", "l"],
|
||||
correct_choice: "a",
|
||||
correct_choice: ["a"],
|
||||
coherent_direction: 180,
|
||||
trial_duration: 1000
|
||||
};
|
||||
@ -116,7 +116,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
type: "rdk",
|
||||
number_of_apertures: 3, //This needs to be set if more than one aperture
|
||||
trial_duration: 10000,
|
||||
correct_choice: "a",
|
||||
correct_choice: ["a"],
|
||||
RDK_type: 3, //Applied to all apertures if only one value
|
||||
aperture_width: 200, //Applied to all apertures if only one value
|
||||
number_of_dots: [50, 200, 100], //Different parameter for each aperture. Array length must equal number_of_apertures
|
||||
|
@ -24,11 +24,11 @@
|
||||
// Create an array of 2 different trials (different conditions)
|
||||
var RDK_trials = [
|
||||
{ // Condition 1
|
||||
correct_choice: 'a', // The correct answer for Condition 1
|
||||
correct_choice: ['a'], // The correct answer for Condition 1
|
||||
coherent_direction: 180 // The coherent direction for Condition 1 (dots move left)
|
||||
},
|
||||
{ // Condition 2
|
||||
correct_choice: 'l', // The correct answer for Condition 2
|
||||
correct_choice: ['l'], // The correct answer for Condition 2
|
||||
coherent_direction: 0 // The coherent direction for Condition 2 (dots move right)
|
||||
},
|
||||
];
|
||||
|
@ -11,7 +11,7 @@ const info = <const>{
|
||||
},
|
||||
/** Array containing the correct key(s) for that trial. */
|
||||
correct_choice: {
|
||||
type: ParameterType.KEYS, // TO DO: docs says this can be array or string - need to allow both types here?
|
||||
type: ParameterType.KEYS,
|
||||
pretty_name: "Correct choice",
|
||||
default: undefined,
|
||||
},
|
||||
@ -554,7 +554,7 @@ class RdkPlugin implements JsPsychPlugin<Info> {
|
||||
response: response.key, //The key that the subject pressed
|
||||
correct: correctOrNot(), //If the subject response was correct
|
||||
choices: choices, //The set of valid keys
|
||||
correct_choice: correct_choice, //The correct choice
|
||||
correct_choice: correct_choice, //The correct choice(s)
|
||||
trial_duration: trial_duration, //The trial duration
|
||||
response_ends_trial: response_ends_trial, //If the response ends the trial
|
||||
number_of_apertures: number_of_apertures,
|
||||
@ -629,26 +629,29 @@ class RdkPlugin implements JsPsychPlugin<Info> {
|
||||
|
||||
//Function that determines if the response is correct
|
||||
const correctOrNot = () => {
|
||||
//Check that the correct_choice has been defined
|
||||
if (typeof correct_choice !== "undefined") {
|
||||
// if single character, convert to array for simplicity
|
||||
if (!Array.isArray(correct_choice)) {
|
||||
correct_choice = [correct_choice];
|
||||
}
|
||||
//Check that the correct_choice has been defined and that it is an array
|
||||
if (typeof correct_choice !== "undefined" && correct_choice.constructor === Array) {
|
||||
if (typeof correct_choice[0] === "string" || correct_choice[0] instanceof String) {
|
||||
var key_in_choices = correct_choice.every((x: string) => {
|
||||
return this.jsPsych.pluginAPI.compareKeys(x, response.key);
|
||||
});
|
||||
return key_in_choices; //If the response is included in the correct_choice array, return true. Else, return false.
|
||||
}
|
||||
//Else if the elements are numbers (javascript character codes)
|
||||
else if (typeof correct_choice[0] === "number") {
|
||||
console.error("Error in RDK plugin: correct_choice value must be a string.");
|
||||
} else if (typeof correct_choice[0] === "number") {
|
||||
// the elements are numbers (javascript character codes)
|
||||
console.error(
|
||||
"Error in RDK plugin: elements in the correct_choice array must be key characters (strings)."
|
||||
);
|
||||
return false; // added due to TS error: not all code paths return a value
|
||||
} else {
|
||||
console.error(
|
||||
"Error in RDK plugin: elements in the correct_choice array must be key characters (strings)."
|
||||
);
|
||||
return false; // added due to TS error: not all code paths return a value
|
||||
}
|
||||
} else {
|
||||
console.error(
|
||||
"Error in RDK plugin: you must specify an array of key characters for the correct_choice parameter."
|
||||
);
|
||||
return false; // added due to TS error: not all code paths return a value
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user