getting trial_duration into the data for a trial (a question from the RT task tutorial) #808
-
I've been working my way through the RT tutorial after rewatching the workshop and doing the lexical decision task with some additional tweaks. In Part 7, a function is added to generate different timings for the fixation cross, but that value is not part of the data generated for that trial. Is there a way to get that value into the data? Somehow I'm not able to get my head around how that value might be accessed. I'm assuming that if I could figure out how to access that value, I would put an on_finish callback function at the end of the definition of the fixation trial type. thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Carolyn, You're right -- this is not a straightforward value to access. I'm hoping to improve the data handling in the future so that any trial parameters can be optionally added onto the data object for a trial. There are a couple workarounds. One is to assign this value to a global variable, and then add it in the var fixation_timing = null; // create global variable
var trial = {
type: 'html-keyboard-response',
stimulus: '<div style="font-size:60px;">+</div>',
choices: jsPsych.NO_KEYS,
trial_duration: function(){
// no var keyword means that it will assign to the global we created outside the trial definition
fixation_timing = jsPsych.randomization.sampleWithoutReplacement([250, 500, 750, 1000, 1250, 1500, 1750, 2000], 1)[0];
return fixation_timing;
},
on_finish: function(data){
data.trial_duration = fixation_timing;
}
} Another option is to use the var trial = {
type: 'html-keyboard-response',
stimulus: '<div style="font-size:60px;">+</div>',
choices: jsPsych.NO_KEYS,
trial_duration: function(){
return jsPsych.randomization.sampleWithoutReplacement([250, 500, 750, 1000, 1250, 1500, 1750, 2000], 1)[0];
},
on_start: function(trial){
trial.data.trial_duration = trial.trial_duration;
}
} |
Beta Was this translation helpful? Give feedback.
Hi Carolyn,
You're right -- this is not a straightforward value to access. I'm hoping to improve the data handling in the future so that any trial parameters can be optionally added onto the data object for a trial.
There are a couple workarounds. One is to assign this value to a global variable, and then add it in the
on_finish
callback.