add properties to all events of a trial #1213
-
Hi all, I've got another very basic question. var mask = {
type: 'image-keyboard-response',
stimulus: 'img/mask.png',
choices: ['space'],
trial_duration: 1000
response_ends_trial: false,
}
var number = {
type: 'html-keyboard-response',
stimulus: function() {
// this is how you can combine different variables from your timeline_variables array
return '<p style="font-size: '+jsPsych.timelineVariable('fontsize', true)+'px;">'+jsPsych.timelineVariable('number', true)+'</p>';
},
choices: ['space'],
trial_duration: 1000,
data: {
condition: jsPsych.timelineVariable('condition')
},
on_finish: function(data){
if(data.condition == 'Go'){
data.correct = jsPsych.pluginAPI.compareKeys(data.key_press, 'space');
} else {
data.correct = jsPsych.pluginAPI.compareKeys(data.key_press, '');
}
}
var fontSize = ['<div style="font-size:48px;">','<div style="font-size:72px;">','<div style="font-size:94px;">','<div style="font-size:100px;">','<div style="font-size:120px;">']
var fontSizeSample = jsPsych.randomization.sampleWithReplacement(fontSize, 12);
var practice = {
timeline: [number, mask],
timeline_variables: [
{number: ""+fontSizeSample[0]+"1</div>", condition: 'Go'},
{number: ""+fontSizeSample[1]+"5</div>", condition: 'Go'},
{number: ""+fontSizeSample[2]+"8</div>", condition: 'Go'},
{number: ""+fontSizeSample[3]+"4</div>", condition: 'Go'},
{number: ""+fontSizeSample[4]+"3</div>", condition: 'NoGo'},
{number: ""+fontSizeSample[5]+"7</div>", condition: 'Go'},
{number: ""+fontSizeSample[6]+"5</div>", condition: 'Go'},
{number: ""+fontSizeSample[7]+"3</div>", condition: 'NoGo'},
{number: ""+fontSizeSample[8]+"9</div>", condition: 'Go'},
{number: ""+fontSizeSample[9]+"2</div>", condition: 'Go'},
{number: ""+fontSizeSample[10]+"1</div>", condition: 'Go'},
{number: ""+fontSizeSample[11]+"8</div>", condition: 'Go'}
],
data: {
'test_part': 'practice'
},
}
var test = {
timeline: [number, mask],
timeline_variables: test_stimuli,
data: {
'test_part': 'test'
}
} Here, the I guess that's a very basic question with a very simple answer :) Alex |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hi Alex, The way that you have the |
Beta Was this translation helpful? Give feedback.
-
In the data, the mask object doesn't not have the property:
That's probably because I add several properties to the mask - I know, that's a very ugly coding, I didn't smooth it for now ;) - : var mask = {
type: 'image-keyboard-response',
stimulus: 'img/mask.png',
choices: function(){
var last_number_key_pressed = jsPsych.data.getLastTrialData().values()[0].key_press;
if (last_number_key_pressed == 32){return ['none'];} else {return ['space'];}
},
trial_duration: function(){
var last_number_rt = jsPsych.data.getLastTrialData().values()[0].rt;
if(last_number_rt > 0){return 1150-last_number_rt;} else {return 900;}
},
response_ends_trial: false,
data: function(){
var last_trial_condition = jsPsych.data.get().last(1).select('condition').values;
return{condition: last_trial_condition};
// var last_test_part = jsPsych.data.get().last(1).select('test_part');
// data.test_part = last_test_part;
},
on_finish: function(data){
var max_rt = jsPsych.data.get().last(2).select('rt').max();
var max_key_press = jsPsych.data.get().last(2).select('key_press').max();
var current_rt = data.rt;
if (current_rt >0){
data.rt = current_rt+250;data.trial_rt=max_rt+250;}else{
data.rt = 0;data.trial_rt=max_rt;}
if(data.condition == 'Go'){
data.trial_correct = jsPsych.pluginAPI.compareKeys(max_key_press, 'space');
} else {
data.trial_correct = jsPsych.pluginAPI.compareKeys(max_key_press, '');
}
}
} The idea is to have an readable row about the trial (a number + a mask) for future analyses as the participant will have the possibility to respond during the number or the mask if he didn't during the number.
|
Beta Was this translation helpful? Give feedback.
-
I replaced this:
in the Thanks! |
Beta Was this translation helpful? Give feedback.
I replaced this:
in the
mask
part of the code by your code and it perfectly works now!(I really don't get the difference, need some javascript lessons I guess!)
Thanks!