Presenting trials according to the answer from the previous trial.

305 views
Skip to first unread message

titusgenis...@gmail.com

unread,
Jul 2, 2019, 1:16:05 PM7/2/19
to jsPsych
Hi Josh and everyone,

I am intending to design an experiment which requires the participants to choose which feedback they will get on the next trial. Normally, the trials have two different feedbacks in two different categories. Now I question them: "From which category do you want to get feedback?" with the normal html-button-response plugin. If they choose A, they should only get the feedback about category A. Same thing applies if they choose B.

I have been trying to access the "button_pressed" from the previous trial.


var skinOrStomach = 99; //flag for the choices

var questionPhase2 = {
type: 'html-button-response',
stimulus: 'Which symptom/reaction do you want to learn more about?',
choices: ['Skin reactions', 'Stomach reactions'],
on_finish: function(data){
if(data.button_pressed == 0) {
skinOrStomach = 0;
}
if(data.button_pressed == 1) {
skinOrStomach = 1;
}
}
};
...
...
for(j = 0; j < 8; j++){
timeline = timeline.concat(questionPhase2);
if(skinOrStomach == 0) { //answer is skin
timeline = timeline.concat(shuffledPhase2Skin);
}
if(dskinOrStomach == 1) { //answer is stomach
timeline = timeline.concat(shuffledPhase2Stomach);
}
}


But the lines above did not seem to work. I have also tried using jsPsych.data.get().select('button_pressed'), it also did not work.

I got the skinOrStomach variable right. However, it did not seem to be able to push the trials to timeline in the "if" conditional. So I only saw the questions for 8 times, without any trials after that. This might be a really simple coding mistake, but does anyone have any idea? Any help would be appreciated.

Thank you in advance!

Best wishes,
Gen

Josh de Leeuw

unread,
Jul 2, 2019, 10:49:06 PM7/2/19
to Genisius Hartanto, jsPsych
Hi Gen,

The problem here is that the for loop is running *before* the study begins. You build the timeline here, but the experiment doesn't run until jsPsych.init() is called.

To achieve what you are after, I recommend using dynamic parameters or conditional timelines.

For conditional timelines, you would create a node like:

var skin_feedback = {
  timeline: [ ... skin feedback trial goes here ... ],
  conditional_function: function(){
    if(skinOrStomach == 0){ return true; } // run the trial
    return false;
  }
}

and also a node for the stomach feedback, and then just add both to the timline. Only one of them will run.

Cheers,
Josh

--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/1a026e9a-1da8-4bc2-a8d3-db81afd9520c%40googlegroups.com.

titusgenis...@gmail.com

unread,
Jul 3, 2019, 12:18:58 PM7/3/19
to jsPsych
I see! The conditional function now works. Thank you for the answer, Josh.

Best,
Gen

Reply all
Reply to author
Forward
0 new messages