Counterbalancing with Batch Session Data
Hello! I'm looking to assign participants to two versions of a task by their order of entry, using batch session data. The code seems to work since Version A and Version B would alternate when I use the same General Multiple link again and again. However, for the first run, the console says "Can send only one batch session patch at a time", and the "counterbalance" counter would be 1 and not 2 on the second run.
Here is the code (the first few lines are probably where the issue is from):
/*start experiment, the JATOS version*/ jatos.onLoad(() => { //use batch session data to do counterbalancing let cb = jatos.batchSession.get("counterbalance"); //retrieve the data console.log("cb initial = "+cb) if(typeof cb == "undefined"){ //deal with the first ever member of the batch? cb = 1; //cb defines if the participant is the nth one in batch jatos.batchSession.add("/counterbalance", cb); } current_cb = cb; console.log("current_cb = " + current_cb) jatos.batchSession.set("counterbalance", cb+1); //add the counter /* initialize jsPsych */ var jsPsych = initJsPsych({ on_trial_start: jatos.addAbortButton, on_trial_finish:function(){ let trial_data_save = jsPsych.data.get().last(1).json();//retrieve data from trial jatos.appendResultData(trial_data_save); //adds data to server as the trial goes }, on_finish: () => jatos.endStudy() //end }); //IMPORTANT: for setting counterbalancing for the rest of the task let counterbalance_main = current_cb % 2; /* task */ let timeline = []; let stimulus = { type: jsPsychHtmlButtonResponse, choices: ['Continue'], stimulus: function(){ //console.log(jatos.batchSession.get) let stim; if(counterbalance_main == 0){ stim = `Version A` } else if (counterbalance_main == 1){ stim = `Version B` } return stim } } timeline.push(stimulus); jsPsych.data.addProperties({ ptp_cb: current_cb }); jsPsych.run(timeline); });
As a beginner in JavaScript and JSON, this might be because I did not really understand the batch session functions 🙈, so perhaps there would be a rather easy fix.
Many thanks for your help!
Comments
Update: the issue might have been resolved! I wonder if there could only be one single line adding information to batch session data for a given script... after adding an else, the counterbalancing began to work for the first run as well:
Hi, neverphack, sorry we didn't reply sooner.
The truth is I don't understand your question. It sounds like you solved your problem.
Let me know if you haven't!
Elisa