Howdy, Stranger!

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

Supported by

Variable ISI - javascript equivalent for python random.randint()?

Hi,

I would usually have a random (constrained) fixation screen duration between stimuli (ISI).

In OpenSesame this works (e.g. for fixation duration approx 1000ms, varied between 750 and 1250ms):

import random

var.fix_duration = random.randint(750, 1250)

Does anyone have examples of how to convert this to OSWeb Inline in order to use it in an online experiment?

Thanks,

Carolyn

Comments

  • Hi @carolyn.

    In javascript most of these functions are located in the Math library. the function Math.random() returns a value between 0 and 1, so you could translate your statement as such:

    vars.fix_duration = parseInt(750 + Math.random()*500)
    

    I hope this helps.

    Buy Me A Coffee

  • Hi Daniel,

    Thank you for the quick response, that works!

    Cheers,

    Carolyn

  • Hi,

    I have a simlar query. I'm converting an experiment to work on OSWEB. I have a variable ISI that ranges between 500-1500 with steps of 100ms.


    The current script is as follows.



    I am not a coder and get buy by finding other peoples codes and modifying where necessary. Any help would be gratefully received.


    Best wishes


    Deiniol

  • Hi @Skilli

    The stepping makes it more difficult. Unfortunately javascript doesn't have a random.choice like function, so you will have to do something like:

    var baseISI = 500
    var increments = 100
    var step = parseInt(Math.random()*10)
    vars.ITI = baseISI + increments*step
    

    That should do the trick.

    Buy Me A Coffee

  • Thanks @Daniel

    This makes alot of sense to me along with the text above. I had to declare the variable ITI at the start of the experiment (see image)


    However, it does not work. I get an invalid duration error message (see image)



    Here is how the code looks in the experiemnt.


  • Hi @Skilli

    You need to place this code in the prepare phase while you put it in the run phase.

    Buy Me A Coffee

  • Good man! Thanks you @Daniel that worked. Just one question, why does code have to go in the prepare phase and not the run phase. From what I understood, declaring variables go in the prepare phase and running code goes in run, as it runs.

    Please excuse stupid questions, I'm trying to learn.


    Thanks again


    Deiniol

  • edited September 2020

    Hi @Skilli,

    The long explanation you can find here: https://osdoc.cogsci.nl/3.3/manual/prepare-run/

    The short explanation: everything in the prepare phase section of script items is executed before the trial starts (i.e. the first display is shown). This is to make sure that potential time consuming calculations do not mess up the timings of the displays when they are shown. So generally, all code that is resource intensive and may take some time to execute should be placed in the prepare phase. Because all other items beside inline scripts also have this prepare phase in which they set themselves up to run, they need to have information about duration etc. already in this phase, and therefore you needed to define the ITI in this phase too.

    Code in the run phase is executed during a trial run. Generally you only place code here that involves the actual presentation of the displays (e.g. `canvas.show()`) or code that is dependent on the response of the participant.

    I hope this helps! (and thanks for the caffeine shot ;) )

    Buy Me A Coffee

  • Thanks @Daniel. Does that means inline script using the prepare phase can go anywhere in the trial sequence?

  • Basically yes. Within a sequence, all prepare phases are executed before all the run phases. So as long as each of the prepare phases does not rely on stuff happening in future prepare phases or any of the run phases, it can go anywhere in the sequence.

    Of course there are some obvious mistakes to make (e.g. using the user response in a prepare phase), but these are usually quickly found.


    Good luck,

    Eduard

    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