Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Java Counterbalance Issue

Hi there,

I have an experiment that i'm hoping to run on osweb. Everything seems to be work smoothly except for the the counterbalancing of the conditions.

My experiment has 2 main conditions: an auditory block (that contains 4 different loops) and a visual block (contains 4 different loops). I want to counterbalance the order of which block the participants sees first.

So far i have this java code:

if(vars.subject_parity === "even"){

vars.condition1 = "AuditoryBlock"

vars.condition2 = "VisualBlock"

}else {

vars.condition1 = "VisualBlock"

vars.condition2 = "AuditoryBlock"


The code works fine in that I don't get any errors. But when i test the experiment and put the subject number an even number, sometimes the I get visual first and sometimes auditory first. Same thing when i try an odd number; sometimes the counterbalancing is right sometimes it's not. I'm not sure what i'm doing wrong.

In the main experimental loop that contains both blocks and their loops i created a variable called condition and put [condition1] in row 1 and [condition2] in row 2.

In the main sequence I set the loop visualBlock to Run If [condition] = VisualBlock and AuditoryBlock to Run If [condition] = AuditoryBlock.

I hope this all make sense.

Any help is greatly appreciated!



  • Hi @Gazelle_M

    Your logic looks right.

    The first thing that I am wondering is: how do you set a subject number? If you specify the subject number in the allowed subject number field, then osweb randomly samples a number from this field.

    Furthermore: are you testing this in jatos or with the option to directly run your experiment in the browser? Jatos has its own system for distributing subject numbers, which you can override, but we'll talk about that when it is applicable.

    Buy Me A Coffee

  • Hi Daniel, 

    Thank you so much for your reply! 

     That’s a very good point. When I click on tools —> osweb, the possible subject numbers are set by default as 0,1. Should I change that? 

    When I run it locally on opensesame (using the double green arrow), if I set the subject number 2 or 4, I get different conditions for each one. Same thing for the web browser option and jatos. When I look at the log the subject parity is odd but the condition is sometimes [condition2] or [condition1]. same thing for even subject parity.  

    I should also mention that i have texts on several sketchpad that i put the show if : [subject_parity] = ‘odd’ or [subject_parity] = ‘even’ 

    These codes always seem to be working in accordance with the subject number. 

    I’m attaching my experiment below. I would appreciate it if you could maybe take a look at it and see if you spot an error. I have a feeling that I did something with specifying the conditions in the main experimental loop and sequence. 

    Thank you so much for your help!  

  • edited August 2020

    Hi @Gazelle_M ,

    I have been dealing with a loooot of counterbalancing issues and your thread captured my attention. I can't be more help than Daniel but I have noticed something that may have a contribution.

    You defined your [condition] variables in rows in the experimental loop as [condition1] and [condition2] and in your sequence looks like this:

    Shouldn't they be named [condition1] = VisualBlock, [condition2] = AuditoryBlock instead? Since you have the javascript code with condition1 and condition2, maybe you could just try adding the 1 and 2 in the run if statement? But your code also has the "else" statement; so the only thing I can comment is that you defined your variables as condition1 and condition2, and then defined another named condition that includes these two, but I think somehow there is a confusion there.

    For a simpler solution maybe; in my experiment (which had no javascript for counterbalancing), I had defined all my variable names as columns. So if my column(thus variable) name was [condition], the rows below them would be VisualBlock and AuditoryBlock, and my run if statement would be as you did in the screenshot.

    For JATOS, if you leave the Possible subject number field empty in the Tools, JATOS uses the subject_nr that itself assigns (which, as far as I noticed, is the component result ID in JATOS).

    As I said, these are just what I learnt from my own adventure and just wanted to share :)



  • Hi @hulya

    Thank you so much for your response.

    unfortunately the problem remains even if i leave the possible subject number blank.

    I also tried your other suggestion, but that didn't seem to work either. OpenSesame skipped all conditions and went straight to the end massage saying " You finished the experiment".

    I'm also encountering another problem: some of my texts are not showing up in the sketchpad, despite the fact that i set the show if to always.

    @Daniel do you have any suggestions?



  • Hi G.

    Regarding the counterbalancing problem: in the counterbalancing inline_javascript, you could add


    below your code. This prints these values to the browser console. If you are using Chrome you can open this with ctrl+shift+i on non-Macs and Cmd+Alt+J on macs. That way you can check if the correct values are assigned to condition1 and 2 depending on subject_parity. At least we then know if subject_parity is correctly interpreted and the conditions are correctly assigned.

    Another thing that I noticed (an this is probably it), is that your order is set to random in the experimental_loop. You need to set this to sequental to let the conditions occur in the order that you specify them.

    Buy Me A Coffee

  • Hi @Daniel

    You were completely right! The problem was that the experimental loop was set to random.

    All issues are resolved now!

    Thank you so much!!!

  • Hi @Gazelle_M

    Glad I could help!

    Buy Me A Coffee

  • edited August 2023

    I know this question has been resolved, but for anyone else who, like me, has returned to this thread multiple times trying to sort out their counterbalancing issues in OSWeb, I'd like to add my experience. I tried using the subject_parity method, but it never worked for me on JATOS, because for some reason subject_parity was always set to `odd`. I also tried leaving the field for possible subject numbers blank, as suggested above, but that didn't work either. What finally did work for me was to slightly modify the suggested counterbalancing script with a function that uses the subject_nr variable that JATOS supplies to check for odd/even, like so:

    function isOdd(num) { return num % 2;}
    if (isOdd(vars.subject_nr) == 1) {
        vars.word_response = "z"
        vars.nonword_response = "m"
    else {
        vars.word_response = "m"
        vars.nonword_response = "z"

    For me, this finally got counterbalancing to work when combining OSWeb with JATOS.

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games