Howdy, Stranger!

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

Supported by

Global variables for several components (based on jspsych)

Hello,

I am programming a study using jspsych. I would love to split the study in several components because I want to allow reloading of the page in some parts of the experiment where participants may have difficulties getting the study run as it requires access to their microphones. However, I do not want them to reload the page during the actual timeline.

Is there a way to set variables globally which I will need in all or most of the components?

I have two versions of my study and depending on a task-variable participants will either see one or the other version. I would like to set this variable once in the beginning but then "transfer" it to the other components where I sometimes have conditional code depending on the version of the experiment.

If there is any other elegant version to solve this issue without having to manually set the version in each component, I would be happy to hear from you.

Thanks!

Comments

  • Hi @penguin, you can use jatos.studySessionData for this. See: http://www.jatos.org/jatos.js-Reference.html#studys-session-data

    Buy Me A Coffee

  • By the way, a lot of people are interested in performing sound recordings in online experiments nowadays, but I keep telling them that this is really difficult due to browser's security restrictions. If you have found an easily reproducible way, would you mind sharing it on the forum? I could even make an announce post of it, so that it stays on top of the list.

    Buy Me A Coffee

  • Hi @penguin ,

    as Daniel said, you can use JATOS' study session to share data between components of the same study. You'd have to set the data in the one component and then in all later component you can access them.

    Another way would be to use the JSON input data in your study's Study Properties:

    Here you can put any JSON and then in your study you can access this via jatos.studyJsonInput. The advantage here is that you can change it comfortably in the JATOS' UI.

    A third possibility is the JATOS' batch session (https://www.jatos.org/Session-Data-Three-Types.html). But the batch session is shared between all runs of your study. Maybe this is not what you want.

    Best,

    Kristian

    Buy Me A Coffee

  • @Daniel I'm just curious why do you think sound recordings in the browser are difficult? What are the security restrictions? Isn't it just a popup from the browser asking the participants if they allow it?

    Buy Me A Coffee

  • It's that you can only record sound after a user's interaction with the browser (so they have to click a button first or press a key; in other words trigger an event, in which stack the audio recording is started). I don't know if they have to do this every time a recording starts (or are you recording the whole session?). Also, do you buffer/save the recording on the user's PC and only send it to the server afterwards? there are some limits to what you can store/how much space you can take up on the clients PC. All in all, there are quite some caveats to get this to work as far as I know, but I have to admit I have never really tried.

    Buy Me A Coffee

  • @Daniel I understand. I'm curious because JATOS since one of the last releases has the possibility to upload files (similar to result data - but whole files) and what I got so far most researchers want to use this feature to record audio or video. I just saw an experiment where little audio snippets were recorded and uploaded, each snipped was just a couple seconds long. This worked quite nicely. In the beginning the browser asked once for an confirmation to record audio. But I've also never tried it with bigger recordings so far.

    Buy Me A Coffee

  • krikri
    edited June 18

    Update: I tried a video recording and uploading of 2 min (17 MB file size) on Chrome and it worked nicely.

    Update 2nd: With video recording of 5 min I had problems: got only HTTP status 400, 'File size too large'.

    Buy Me A Coffee

  • Cool! Well that's doable I think? What library did you use or just barebone Javascript? Do you think you could write a short manual or tutorial about how you did this?

    Buy Me A Coffee

  • I just wanted a proof of concept. I used the example from https://github.com/muaz-khan/RecordRTC and adapted it for jatos.js. It's in the JATOS Example Studies: "Video Recording - Record a video with the webcam and upload the data as a file to JATOS".

    Buy Me A Coffee

  • Thanks for your answers, I used the JSON Input in the Jatos UI for my purpose and it works. However, as I have some code for the audio set up which is "outside" the jatos.onload-function, I am not able to do it for all the variables but I can live with that.

  • edited June 23

    Hi there,

    I need your help again. When I just defined one global variable in the Jatos UI, it worked fine. However, I now defined two variables and this leads to problems and in the experiment these variables seem to be not defined.

    Here is the code I enter in the Jatos UI:

    { "var1": true,
    
     "var2": 0}
    


    Here, I call the variables in the experiment:

    jatos.onLoad(function() {
    
    global_variables =jatos.studyJsonInput;
    
    
    
    
    var task = global_variables.var1;
    
    console.log(task);
    
    var order = global_variables.var2;
    
    console.log(order);
    
    jsPsych.init({
    
     timeline: timeline,
    
          on_finish: function() {
    
             var resultJson = jsPsych.data.get().json();
    
             jatos.submitResultData(resultJson, jatos.startNextComponent);
    
          }
    
       });
    
    })
    

    The console.log is giving me the correct variable values: "true" and "0". However, they can not be used by the jspsych-timeline and I get the following warning for either of the two variables (it is much longer but I think this is the most important part):

    jQuery.Deferred exception: var1 is not defined conditional_function@http://127.0.0.1:9000/publix/65/420/start?srid=1147:138:6

    As I have trials which are put in the timeline depending on which value is defined for the variables, the whole experiment does not start. When I just wrote "true" in the UI and later on used

    var1=jatos.studyJsonInput;

    (and defined the second variable locally = I only defined one variable globally), everything worked smoothly.

    How can I get this working?


    Furthermore, I wanted to know how to set the variables to a random number in the User Interface (similar to the code like this from inside the jspsych-experiemnt):

    var resp = Math.round(Math.random());
    

    By the way, I was not able to find examples in the documentation how "proper" UI-input might look like. I would have loved to have this feature or a link referring to a good source as I assume that many people running experiments online have only little experience and knowledge in programming.

  • Hi @penguin,

    please use proper source code formatting for code and don't post it as unformatted text. I have changed your post this time to do this. This makes it more easier for us to read, and we get syntax highlighting for free.

    You define the variables in the jatos.onLoad function, but the timeline variable is defined outside of it. If you want the variables to be available in the timeline too, then the timeline and all its components should be defined inside the jatos.onLoad too.

    Furthermore, I wanted to know how to set the variables to a random number in the User Interface (similar to the code like this from inside the jspsych-experiemnt):

    You cannot set random variables in the jatos UI as the input is pure JSON and thus can only contain literal information, and no JavaScript or function calls to for instance random.

    Buy Me A Coffee

  • I agree with Daniel. Move the timeline definition inside the jatos.onLoad and it should work. You can use the jatos.studyJsonInput only after jatos.js' onLoad event is fired and to wait for this one must use the jatos.onLoad function.

    Buy Me A Coffee

  • I figured out that my problem is not related to where I define the timeline. As posted above, I called jatos.studyJsonInput after jatos.onLoad and the timeline is called in the jsPsych.init-function which is nested in the jatos.onLoad-function.

    The component runs without any problems when I do not save the elements of the global_variables_objects like posted above but without defining it as a variable:

    task = global_variables.var1;
    order = global_variables.var2;
    

    Though I do not fully understand why this is the case I am happy that it is working now!

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