Howdy, Stranger!

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

Supported by

Running experiments online using OSWeb

Hi,

I have been using Opensesame for several years and it worked really well. I am now trying to run a lexical decision study online, but I had the following error:

uncaught typeerror: cannot read properties of undefined (reading 'apply') see the console for further details


The source of the error seems to be my two in-line scripts: one for recording the handness of participants (so that they pressed the 'yes' button with their dominant hand), the other is to counterbalance.


In-line script 1:

if var.response_handedness_response =='l':

var.y_response='z'

var.n_response='m'


else:

var.y_response='m'

var.n_response='z'


In-line script 2:

if self.get('subject_nr')%8 == 1:

b1 = 0

b2 = 10

b3 = 10

b4 = 10

b5 = 10

b6 = 10

b7 = 10

b8 = 10

elif self.get('subject_nr')%8 == 2:

b1 = 10

b2 = 0

b3 = 10

b4 = 10

b5 = 10

b6 = 10

b7 = 10

b8 = 10

elif self.get('subject_nr')%8 == 3:

b1 = 10

b2 = 10

b3 = 0

b4 = 10

b5 = 10

b6 = 10

b7 = 10

b8 = 10

elif self.get('subject_nr')%8 == 4:

b1 = 10

b2 = 10

b3 = 10

b4 = 0

b5 = 10

b6 = 10

b7 = 10

b8 = 10

elif self.get('subject_nr')%8 == 5:

b1 = 10

b2 = 10

b3 = 10

b4 = 10

b5 = 0

b6 = 10

b7 = 10

b8 = 10

elif self.get('subject_nr')%8 == 6:

b1 = 10

b2 = 10

b3 = 10

b4 = 10

b5 = 10

b6 = 0

b7 = 10

b8 = 10

elif self.get('subject_nr')%8 == 7:

b1 = 10

b2 = 10

b3 = 10

b4 = 10

b5 = 10

b6 = 10

b7 = 0

b8 = 10

b9 = 10

else:

b1 = 10

b2 = 10

b3 = 10

b4 = 10

b5 = 10

b6 = 10

b7 = 10

b8 = 0


exp.set('b1',b1)

exp.set('b2',b2)

exp.set('b3',b3)

exp.set('b4',b4)

exp.set('b5',b5)

exp.set('b6',b6)

exp.set('b7',b7)

exp.set('b8',b8)


I deleted the first online script and changed the second into the following Javascript using an online converter, but I still got the same error message.

var b1, b2, b3, b4, b5, b6, b7, b8, b9;


if (this.get("subject_nr") % 8 === 1) {

 b1 = 0;

 b2 = 10;

 b3 = 10;

 b4 = 10;

 b5 = 10;

 b6 = 10;

 b7 = 10;

 b8 = 10;

} else {

 if (this.get("subject_nr") % 8 === 2) {

  b1 = 10;

  b2 = 0;

  b3 = 10;

  b4 = 10;

  b5 = 10;

  b6 = 10;

  b7 = 10;

  b8 = 10;

 } else {

  if (this.get("subject_nr") % 8 === 3) {

   b1 = 10;

   b2 = 10;

   b3 = 0;

   b4 = 10;

   b5 = 10;

   b6 = 10;

   b7 = 10;

   b8 = 10;

  } else {

   if (this.get("subject_nr") % 8 === 4) {

    b1 = 10;

    b2 = 10;

    b3 = 10;

    b4 = 0;

    b5 = 10;

    b6 = 10;

    b7 = 10;

    b8 = 10;

   } else {

    if (this.get("subject_nr") % 8 === 5) {

     b1 = 10;

     b2 = 10;

     b3 = 10;

     b4 = 10;

     b5 = 0;

     b6 = 10;

     b7 = 10;

     b8 = 10;

    } else {

     if (this.get("subject_nr") % 8 === 6) {

      b1 = 10;

      b2 = 10;

      b3 = 10;

      b4 = 10;

      b5 = 10;

      b6 = 0;

      b7 = 10;

      b8 = 10;

     } else {

      if (this.get("subject_nr") % 8 === 7) {

       b1 = 10;

       b2 = 10;

       b3 = 10;

       b4 = 10;

       b5 = 10;

       b6 = 10;

       b7 = 0;

       b8 = 10;

       b9 = 10;

      } else {

       b1 = 10;

       b2 = 10;

       b3 = 10;

       b4 = 10;

       b5 = 10;

       b6 = 10;

       b7 = 10;

       b8 = 0;

      }

     }

    }

   }

  }

 }

}


exp.set("b1", b1);

exp.set("b2", b2);

exp.set("b3", b3);

exp.set("b4", b4);

exp.set("b5", b5);

exp.set("b6", b6);

exp.set("b7", b7);

exp.set("b8", b8);


I am now unsure of what to do to solve the error. Do you have any suggestions? Thanks so much in advance!

Comments

  • FabFab
    edited December 2022

    Hi @Yuyanxue,

    Just a quick comment... Would need to try your program to be sure but it looks like you're trying to use Python code into your Inline_Javascript objects... "this.get" and "exp.set" are Python commands.

    To access the subject number in Javascript, use vars.subject_nr. To set a variable's value task-wise, replace exp.set by vars. For example: exp.set("b1", b1) becomes vars.b1=b1.

    That's my first suggestion anyway. Try it out to see if it helps...

    Best,

    Fabrice.

    PS: please note that it is best to post messages related to OSweb to the OSWeb forum. I'm moving this thread to that forum so that it can benefit other OSWeb users too.

    Buy Me A Coffee

  • Hi Fabrice,


    Thanks a lot for your suggestion. I have replaced exp.set by vars, but the same error occurred. Also, when I tried to run the experiment without the two in-line scripts, another error message occurred:

    "Uncaught ReferenceError: Variable 'y_response' not present in var store

    See the console for further details".

    'y_response' is a variable specified in one of the in-line script, and also in the stimuli table.


    I have attached a simpler version of the experiment which only had one trial in each block (four blocks per list). It has two in-line scripts: one is "handedness_script" and the other is "counterbalance". The experiment worked perfectly using Opensesame, but couldn't run in OSWeb.

    Could you please help solve the problems?

    Thanks a lot,

    Mengzhu

  • Hi @Yuyanxue,

    First, many thanks for the ☕️! very nice of you. It's very much appreciated!

    Second, just for your information, when addressing messages to specific forum users in the forum, it helps using their handle. You can do so by typing "@" and the first letters of the users name. A pull down menu then appears, which you can use to select the user you're addressing the message to. For example, if I type @Yu, the following appears:

    Using handlers means that your correspondent gets a notification when they visit the forum. As there can be many message posted on the forum, using my handler ensures that I'm more likely to see taht there is a message for me.

    Third, moving on to your task... I had a quick look at the task you sent me. I could see that many objects were inline_script objects containing Python code. These need to be replaced by inline_Javascript objects containing Javascript code doing the equivalent of what your Python code was using. Sometimes it is relatively easy, sometimes it is harder (for example when it comes to shuffling an array). You then must make sure to delete the inline_script objects containing Python code and make sure to permanently erase them from the unused objects (otherwise,, even though you're no longer using these objects, the task will still try to interpret them and the task won't run in a browser).

    A lot of the rewriting follows the instructions I gave you in my earlier message. That is, instead of using self.get, you'd use vars. So, for example, self.get('subject_nr') in Python becomes vars.subect_nr in Javascript.

    Your couterbalance oinline_script code:

    ... needs to be rewritten in Javascript within an inline_Javascript object. Your original code was quite redundant (all b variables are equal to 10 except one, depending on the subject's number). I simplified it as follows:

    // I've simplified your approach to something simpler to remove redundancies.redundancies
    // Since the conditions are ony used to change the value of one variables, it is simpler to
    // set them all to 10 and then only modify the appropriate one to 0
    
    var b1 = 10 // omitting the "var" bit will work when running the task in OS but not in a browser
    var b2 = 10
    var b3 = 10
    var b4 = 10
    var b5 = 10
    var b6 = 10
    var b7 = 10
    var b8 = 10
    
    if (vars.subject_nr%8 == 1) {
        b1 = 0
    } else if (vars.subject_nr%8 == 2) {
        b2 = 0
    } else if (vars.subject_nr%8 == 3) {
        b3 = 0
    } else if (vars.subject_nr%8 == 4) {
        b4 = 0
    } else if (vars.subject_nr%8 == 5) {
        b5 = 0
    } else if (vars.subject_nr%8 == 6) {
        b6 = 0
    } else if (vars.subject_nr%8 == 7) {
        b7 = 0
    } else {
        b8 = 0
    }
    
    vars.b1=b1
    vars.b2=b2
    vars.b3=b3
    vars.b4=b4
    vars.b5=b5
    vars.b6=b6
    vars.b7=b7
    vars.b8=b8
    


    The shuffling of the block_list array is a little harder because Javascript does not contain an already existing shuffling function. In Python, it is easy to import one ("from random import shuffle"), but in Javascript, you must create and declare such function to then be able to call it. There are various ways to shuffle an array in Javascript. Some are compatible with EC5 and others only with EC6 (see this webpage for a discussion of the difference: https://www.javatpoint.com/es5-vs-es6). As fas as I know, it is best to use methods compatible with EC5 for the moment (as I believe that OSWeb does not yet support EC6).

    I rewrote your randomisation code into an inline_Javascript object as follows:

    function arrShuffle(a) { 
      var j, x, i;
      for (i = a.length - 1; i > 0; i--) {
        j = Math.floor(Math.random() * (i + 1));
        x = a[i];
        a[i] = a[j];
        a[j] = x;
      }
      return a;
    }
    
    // create a list of the number of blocks that you need. Always start at 0. Here I have eight blocks.
    const block_list = [0,1,2,3,4,5,6,7]
    
    // Shuffles the array just declared
    arrShuffle(block_list)
    
    // create variables that will be used to help randomize later in your MainSequence. The number of variables depends on the number of blocks you have in your experiment (and should correspond to how many are in the block_list).
    
    var Litem0 = block_list[0]
    var Litem1 = block_list[1]
    var Litem2 = block_list[2]
    var Litem3 = block_list[3]
    var Litem4 = block_list[4]
    var Litem5 = block_list[5]
    var Litem6 = block_list[6]
    var Litem7 = block_list[7]
    
    // Make these variables part of the experiment
    
    vars.L0=Litem0
    vars.L1=Litem1
    vars.L2=Litem2
    vars.L3=Litem3
    vars.L4=Litem4
    vars.L5=Litem5
    vars.L6=Litem6
    vars.L7=Litem7
    

    Note: Your task structure is quite complex. I suspect it could be simplified, but this is outside the help I can provide. Seeing that you're using 8 blocks, I did take the liberty of creating a block_list array with 8 elements and to create variables L0 to L7. Please revise and modify as needed.

    This was not enough, however... When testing your task in OSWeb it is important to try it through your browser (making the console visible; CTRL+i, helps tracking what is going on and identify problems, or at least sometimes). Some features of the task worked in OS but not in OSWeb. Such things can be as little as not declaring variables in a way Javascript likes. So, for example, b1 = 10 will run when the task is executed in OS, but it will generate an error (saying that the variable is not defined when running it in OSWeb). Hence, it needs to be var b1=10. Always testing your task through OSWeb as you develop it will help detecting possible problems (if you develop it and test it only through OS, you may then have to do quite a lot of debugging as I had to do with your task).

    Also, you were also using Python code in the "Run if" conditions of numerous sequences. For example:

    Expressions such as self.get are Python instructions. They will work when you run the task in OS:

    ... but not when you run it through the browser (i.e., when using OSWeb):

    So, all of the "run if" conditions need to be rewritten to avoid Python code:

    I had to do the same for all block_seq sequences, as well as for the mainsequence.

    Finally, when testing your task through the browser, OSWeb will run a compatibility check and highlight certain problems.

    For example, in OSWeb, the logger cannot be set to record all variables (this is because this would take a lot of resources and bandwidth in a browser), so the logger must be set manually. To test your task in a browser, I therefore had to disable the "Log all variables" option. You'll need to make sure to add manually all the variables you want to feature in the data log. Using the variable inspector can help greatly doing so.

    I attach my modification of the task you posted in this forum:

    The explanations above and the code should allow you to follow all the changes I made. I'm non holidays but decided to take a moment to go through this so that you can progress with your task, but please note that I did not test the whole task and that I'm not familiar with your design or objectives, so please complete and modify the task as required and make sure to check thoroughly your task and data output before using the task with real participants.

    Hope this helps.

    Kind regards,

    Fabrice.

    Buy Me A Coffee

  • Hi Fabrice @Fab

    Thanks so much for your detailed explanations and for taking the time to help! Very much appreciated.

    The explanations are really helpful, and the changes needed were much more complicated than I thought. I have run your modified version in OSWeb and it works perfectly. I will process your explanations and complete and test the whole experiment.


    Happy new year!

    Best,

    Mengzhu

  • Hi @Fab ,


    Thanks very much again for your help. I have constructed the whole experiment and it worked in my browser fine. However, when my collaborator tried to run the experiment on the web, she got an error "compatibility check failed"... Do you have an idea about what might be going wrong?


    Our counterbalance-Javascript (thanks again for helping convert and simplify the original python script to this Java one!) distributes participants into 8 different groups - the1st/9th participant would get List 1, and the 8th/16th participant gets List 8 etc.. As the OSWeb did not ask to enter the subject number (OS does), although we have specified the possible subject numbers to [0,1,2,3,4,5,6,7], we are not sure whether the first participant who clicked the link would be assigned to List 1, and the 9th participant would still be assigned to List 1?

    Also, our experiment exceeds largely the recommended size, and I tried to deploy it once in Jatos TryOut Server, the loading time was indeed quite long. As our experiment collects reaction times data, would loading time (and logging too many variables) affect the recording/accuracy of participants' reaction times?

    Thanks very much in advance!

    Best regards,

    Mengzhu

  • Hi @Yuyanxue,

    I'm glad my help was of use and that your experiment is now almost running.

    To answer your questions, the subject number will be randomly allocated by the program, which means that it is not possible to ensure that you get the same number of participants with id numbers 0 to 7. There currently is no easy solution to that problem. the issue is that the task runs on the participant's machine and not on a central server. This allows for proper temporal resolution and makes the task a lot more reliable, but the downside is that each individual instance of the task has no way of knowing hoe many participants have been tested with each id across all the different computers participants have used across various locations. If you have a set list of participants to invite to take part, one thing you can try, to try to get roughly similar numbers in each of the 8 conditions, is to modify the task to ask participants to enter an id number and instruct individual beforehand to use such or such number. However, in most cases this is not practical to do.

    As for the size of the task, it should not affect the accuracy of RTs but it will affect the time it takes for the task to load up when it starts. Most people have a relatively fast connection speed, so that should not be an issue.

    The time taken to log the data is fairly short but will vary depending on the number of variables you want to collect (for this reason, OSWeb requires the "log all variables" to be disabled). Unless you're logging tens of variables, this should not be an issue.

    Hope this helps.

    Kind regards,

    Fabrice.

    Buy Me A Coffee

  • Dear @Fab


    Thanks very much again for your detailed suggestions. As for the size of the experiment, I have changed all sound files from .wav to .mp3 tp reduce the size, but the experiment returned the following error right after a few sketchpads indicating experiment instructions and before the inline java script:

    Uncaught TypeError: Cannot read properties of null (reading 'cloneNode')

    See the console for further details


    Does this mean that OSWeb does not support mp3 files?

    Thanks in advance!

    Best regards,

    Mengzhu

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 http://45.77.173.118/ 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