mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
update locations in docs where keyCode is used
This commit is contained in:
parent
6a2dc21bc8
commit
74fae253cc
@ -337,7 +337,7 @@ var trial = {
|
|||||||
var loop_node = {
|
var loop_node = {
|
||||||
timeline: [trial],
|
timeline: [trial],
|
||||||
loop_function: function(data){
|
loop_function: function(data){
|
||||||
if(jsPsych.pluginAPI.convertKeyCharacterToKeyCode('r') == data.values()[0].key_press){
|
if(data.values()[0].key_press == 'r'){
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -367,7 +367,7 @@ var if_node = {
|
|||||||
// get the data from the previous trial,
|
// get the data from the previous trial,
|
||||||
// and check which key was pressed
|
// and check which key was pressed
|
||||||
var data = jsPsych.data.get().last(1).values()[0];
|
var data = jsPsych.data.get().last(1).values()[0];
|
||||||
if(data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode('s')){
|
if(data.key_press == 's'){
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -863,12 +863,12 @@ var test = {
|
|||||||
choices: ['f', 'j'],
|
choices: ['f', 'j'],
|
||||||
data: jsPsych.timelineVariable('data'),
|
data: jsPsych.timelineVariable('data'),
|
||||||
on_finish: function(data){
|
on_finish: function(data){
|
||||||
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
|
data.correct = data.key_press == data.correct_response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `data.key_press` value is a numeric key code indicating which key the subject pressed. The function `jsPsych.pluginAPI.convertKeyCharacterToKeyCode` converts the character representation of a key into the numeric representation (e.g., calling the function on the value `'f'` generates the value `70`). If this numeric value matches `data.key_press` then `data.correct` will be `true`. Otherwise, it will be `false`.
|
The `data.key_press` value is a string representation of the key the subject pressed. We can compare this with the `data.correct_response` value, and assign this computer value to a new property `data.correct`.
|
||||||
|
|
||||||
### The complete code so far
|
### The complete code so far
|
||||||
|
|
||||||
@ -936,7 +936,7 @@ The `data.key_press` value is a numeric key code indicating which key the subjec
|
|||||||
choices: ['f', 'j'],
|
choices: ['f', 'j'],
|
||||||
data: jsPsych.timelineVariable('data'),
|
data: jsPsych.timelineVariable('data'),
|
||||||
on_finish: function(data){
|
on_finish: function(data){
|
||||||
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
|
data.correct = data.key_press == data.correct_response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1064,7 +1064,7 @@ This code is available in the examples folder in the jsPsych download. It is cal
|
|||||||
choices: ['f', 'j'],
|
choices: ['f', 'j'],
|
||||||
data: jsPsych.timelineVariable('data'),
|
data: jsPsych.timelineVariable('data'),
|
||||||
on_finish: function(data){
|
on_finish: function(data){
|
||||||
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
|
data.correct = data.key_press == data.correct_response;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
var loop_node = {
|
var loop_node = {
|
||||||
timeline: [trial],
|
timeline: [trial],
|
||||||
loop_function: function(data){
|
loop_function: function(data){
|
||||||
if(jsPsych.pluginAPI.convertKeyCharacterToKeyCode('r') == data.values()[0].key_press){
|
if(data.values()[0].key_press == 'r'){
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -40,7 +40,7 @@
|
|||||||
timeline: [if_trial],
|
timeline: [if_trial],
|
||||||
conditional_function: function(){
|
conditional_function: function(){
|
||||||
var data = jsPsych.data.get().last(1).values()[0];
|
var data = jsPsych.data.get().last(1).values()[0];
|
||||||
if(data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode('s')){
|
if(data.key_press == 's'){
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
choices: ['f', 'j'],
|
choices: ['f', 'j'],
|
||||||
data: jsPsych.timelineVariable('data'),
|
data: jsPsych.timelineVariable('data'),
|
||||||
on_finish: function(data){
|
on_finish: function(data){
|
||||||
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
|
data.correct = data.key_press == data.correct_response;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,9 +88,9 @@
|
|||||||
},
|
},
|
||||||
on_finish: function(data){
|
on_finish: function(data){
|
||||||
if(data.word_validity == 'valid'){
|
if(data.word_validity == 'valid'){
|
||||||
var correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode('y');
|
var correct = data.key_press == 'y';
|
||||||
} else {
|
} else {
|
||||||
var correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode('n');
|
var correct = data.key_press == 'n';
|
||||||
}
|
}
|
||||||
data.correct = correct;
|
data.correct = correct;
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,8 @@ jsPsych.plugins['reconstruction'] = (function() {
|
|||||||
|
|
||||||
//console.log('fire');
|
//console.log('fire');
|
||||||
|
|
||||||
var key_i = (typeof trial.key_increase == 'string') ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.key_increase) : trial.key_increase;
|
var key_i = trial.key_increase;
|
||||||
var key_d = (typeof trial.key_decrease == 'string') ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.key_decrease) : trial.key_decrease;
|
var key_d = trial.key_decrease;
|
||||||
|
|
||||||
// get new param value
|
// get new param value
|
||||||
if (info.key == key_i) {
|
if (info.key == key_i) {
|
||||||
|
@ -124,8 +124,8 @@ jsPsych.plugins['same-different-html'] = (function() {
|
|||||||
|
|
||||||
var correct = false;
|
var correct = false;
|
||||||
|
|
||||||
var skey = typeof trial.same_key == 'string' ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.same_key) : trial.same_key;
|
var skey = trial.same_key;
|
||||||
var dkey = typeof trial.different_key == 'string' ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.different_key) : trial.different_key;
|
var dkey = trial.different_key;
|
||||||
|
|
||||||
if (info.key == skey && trial.answer == 'same') {
|
if (info.key == skey && trial.answer == 'same') {
|
||||||
correct = true;
|
correct = true;
|
||||||
|
@ -125,8 +125,8 @@ jsPsych.plugins['same-different-image'] = (function() {
|
|||||||
|
|
||||||
var correct = false;
|
var correct = false;
|
||||||
|
|
||||||
var skey = typeof trial.same_key == 'string' ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.same_key) : trial.same_key;
|
var skey = trial.same_key;
|
||||||
var dkey = typeof trial.different_key == 'string' ? jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.different_key) : trial.different_key;
|
var dkey = trial.different_key;
|
||||||
|
|
||||||
if (info.key == skey && trial.answer == 'same') {
|
if (info.key == skey && trial.answer == 'same') {
|
||||||
correct = true;
|
correct = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user