Howdy, Stranger!

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

Supported by

Logging a variable defined in inline_javascript

Hi everyone,

I'm just starting out with OpenSesame and, so far, have been able to customise my (OSWeb-friendly) experiment with some JavaScript. However, I seem to be running into an issue when it comes to logging the values of variables that I define in the inline_javascript environment. As an example, here is the trial routine of my experiment:


Basically, the participant will make a choice between two monetary options ('options' and 'keyboard_response') and I want to store the participant's earnings in an array , so that I can randomly select one of the earnings at the end of the experiment and pay bonus payment based on its value. Because this is a risky choice task (e.g. 100% probability of winning 10, or a 60% probability of winning 20), I need to calculate the actual earning (i.e., whether the 'risky' option yielded a reward of 20 or 0) with custom code, which happens in the 'earning_computation' component:

So far so good, the code seems to work because when I display the feedback with the actual earning ('feedback_risky/'feedback_safe' components), I call the 'earning' variable in the text via [earning] and the correct value is displayed. However, for some reason this value is not getting stored by OpenSesame - I added 'earning' into the 'logger' explicitly and I can see the variable in my output data. However, the value of this variable is always 0 across any and all trials. Moreover, I tried to define the value of the 'earning' variable at the beginning of the experiment, just to see that works:

But that doesn't cut it either, since the output data file still shows that 'earning' is 0 from the very first trial (despite me setting the value to 1 in the Prepare section above). My question is, am I doing something wrong here, or does OpenSesame simply not register the values of inline_javascript-defined variables during logging?

Comments

  • Hi,

    Sounds weird. I guess you always end up in your else statement? Can you share your experiment, so i can have a closer look? What is the script earning_logging doing?


    Eduard

    Buy Me A Coffee

  • Hi eduard, thank you for your quick reply! Please find attached the experiment file in this post.

    It does seem as if the experiment ultimately always went to the else part, but the output of the 'earning' variable displayed in the feedback_... components is not always zero, indicating that the correct 'earning' value is passed on - it just doesn't seem to be getting logged correctly, for whatever reason

    And the 'earning_logging' is just a script where I wanted to define the array that should store all the earnings (Prepare phase: vars.earning_array = new Array), and where I would append the current trial's earning value (Run phase: vars.earning_array.push(vars.earning) ). I would have incorporated it in the 'earning computation' script, but I will have multiple conditions/loops in my experiment and I only want to run this part of the script in certain ones, which is why I decided to keep it in a separate script (to control this via the routine 'runif' statements)


  • Hi @ErikS

    I was just reading this thread and @eduard's comment about always ending up with the else statement, I had a look at your conditions in that if, else if, else structure. I did some testing and, indeed, this is what is happening. I'm not familiar with the sometimes function you're using in your code and couldn't find anything online. I can't see the function being declared in your code either. Could it be that the function is unknown and so the conditions are not met, and so you end up with the else statement?

    Fabrice.

    Buy Me A Coffee

  • Hi Erik,

    Where do you run the experiment? In the browser or in the GUI? As far as I can see, the sometimes function is not defined when you run it in the GUI, but I don't find the log file when you execute it online in the browser. Do you happen to know where I can find the log file?

    @Fab the sometimes function comes with Opensesame ;)

    Eduard

    Buy Me A Coffee

  • Thank you very much for your answer, @Fab . The 'sometimes' function was listed on the OpenSesame website as one of the common functions (https://osdoc.cogsci.nl/3.3/manual/javascript/common/), so I assumed it would be safe to use - I thought it would generate a random variable between 0 and 1, and if it's higher than the p parameter, then the function returns TRUE, otherwise FALSE, so I wrote my if/else loops with this in mind. However, no matter how I rearranged the loops, the variable values would not get stored. So it could be that my assumption was wrong and that this function would need to be explicitly declared/I would need to load a package in order to use it (even though the OS website does not mention anything along those lines). Anyway, my initial problem is solved - I simply used Math.random instead and voila, everything works as intended! Again, thank you very much for helping me narrow down the issue, I appreciate it a lot

  • Hi @ErikS,

    I didn't know the sometimes function. Just tried it out with a basic example and it does work within OpenSesame:

    if (sometimes(.5)) {
      console.log('Sometimes you win')
    } else {
      console.log('Sometimes you lose')
    }
    

    Not sure why it didn't work in the context of your experiment but I might have an idea... In the above example you can see that sometimes(.5) will be true half the time and false have the time (on average, that is). If think it it designed to be used by itself and that it can never be true in conjunction with another variable. I can't quite get my head around the exact logic underpinning my intuition, but I tested it out empirically with just one inline_javascript object as a task, nothing else:

    a="ok"
    for (let i = 0; i < 100; i++) {
      if (a=="ok" && sometimes(.5)) {
           console.log('Sometimes you win')
       } else {
           console.log('Sometimes you lose')
      }
    }
    

    It basically runs a simple "if...then" loop 100 times using a two arguments condition. The first condition is that a="ok" (which it always is in this code), and the second uses the sometimes function. If you run it, you'll see that the condition is never met. In fact, even if you change sometimes(.5) to sometimes(1), the condition is never true.

    So, conclusion: the sometimes function is indeed included in OpenSesame, but apparently designed to be used by itself (multiple argument conditions using it don't appear to ever be true).

    So, you did well using the Math.random alternative!

    Good luck with your experiment!

    Fabrice.

    Buy Me A Coffee

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