jeudi 28 janvier 2021

Jspych- How to use randomization module in feedback variable following a image-button-response trial?

I am creating a task using Jpsych in which participants are shown an image and decide to either press either one of two buttons (PRESS vs NO PRESS). Depending on the button they press, they will be shown another image (stimuli A or stimuli B) drawn at random. I have the following code:

var button_pressed= [light_on1, light_on2, light_on3, light_on4, light_on5, light_on6, light_off1, light_off2, light_off3, light_off4];
var button_notpressed= [light_on7,light_on8,light_on9,light_on10,light_on11,light_on12,light_off5,light_off6,light_off7,light_off8];
var button_pressed_sample = jsPsych.randomization.sampleWithoutReplacement(button_pressed, 1);
var button_notpressed_sample = jsPsych.randomization.sampleWithoutReplacement(button_notpressed, 1);

 var timeline= [];

var trial_one = {
    type: 'image-button-response',
    stimulus: light_off,
    choices: ['PRESS','NO PRESS'],
    trial_duration: 3000,
    on_finish: function(data){
        if(data.key_press== 0){
        data.correct= true;
    } else {
        data.correct=false;
    }
}
}
var feedback_one = {
    type: "image-keyboard-response",
    trial_duration: 2000,
    stimulus:function(){
        var last_trial_correct=jsPsych.data.get().last(1).values()[0].correct;
        if (last_trial_correct){
            return button_pressed_sample;
        } else {
            return button_notpressed_sample
    }
    }
}
timeline.push(trial_one,feedback_one);

As of now, the code executes, but the stimuli are not being randomized in response to button press. Either all of the feedback stimuli are feedback A or all are feedback B. The code does not seem to be randomly sampling without replacement as I tried to indicate. Any help would be greatly appreciated!!




Aucun commentaire:

Enregistrer un commentaire