Howdy, Stranger!

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

Supported by

Executing experimental items using Javascript?

Hi all,

I'm designing a color-shape switching task in OSWeb, but it turns out I need some help with Javascript.

In my experiment, I want the practice loop to repeat when participants score under a certain percentage. In a previous version of my experiment, I successfully programmed this using Python. To repeat the practice loop I inserted an inline_script after the practice loop and told the script to execute the practice_loop again using the items.execute() function when var.repeat is set to 1. I tried programming this using Javascript (see below), but when running this code, the debugging console tells me that the 'items' function is undefined. Am I correct in assuming that I can't call the 'items' function with Javascript? If yes, is there another way to program this using Javascript? Or is there a (probably obvious) error in my code that prevents the script from running correctly?

inline_javascript after the 'keyboard_response' item to track accuracy in the trial sequence

// TRACK ACCURACY: Repeat practice?
if (vars.acc >= 75){
vars.repeat = 0
} else if (vars.acc < 75){
vars.repeat = 1
}

inline_javascript after the practice_loop to repeat the practice block

if (vars.repeat == 1){ // if the practice needs to be repeated
// show instruction screen again
if (vars.task === "shape"){ // when current task is shape
items.execute("shape_intro"); // run shape instructions
} else if (vars.task === "color"){ // when current task is color
items.execute("color_intro"); // run color instructions
} else if (vars.task === "mixed"){ // when current task is mixed
items.execute("mixed_intro_2"); // run mixed instructions
}
items.execute("reset_feedback"); // always run reset_feedback item
if (vars.task === "shape" || "color"){ // if the task is shape or color
items.execute("single_prac_loop"); // run single_prac_loop
} else if (vars.task === "mixed"){ // if the task is mixed
items.execute("mixed_prac_loop"); // run mixed_prac_loop
}
} else if (vars.repeat == 0){ // continue as normal
// pass
}

I attached the .osexp so you can hopefully get an idea of what I'm referring to (somehow I'm not able to indent the code in this post). Let me know if you need any further information!

Comments

  • I think you could use a 'repeat_cycle' item in the experiment structure and add a condition to its run-if statement in the sequence item. E.g. run if: [repeat] == 1. Good luck!

  • edited February 2021

    Hi @favdberg ,


    Am I correct in assuming that I can't call the 'items' function with Javascript? 

    Yes, this is correct. See also here:

    If yes, is there another way to program this using Javascript?

    Yes, as @JasperdeWaard suggested, you could use the repeat variable in a repeat_cycle item. However, you will probably have to redesign the hierarchy of your experiment a bit, such that the practice phases have an extra loop-sequence wrapped around them. Like so:


    Next, as Jasper suggested, you can set "Repeat if" to

    [repeat] = 1
    

    When looking at your script, I also noticed a few other things:

    1. The variable correct_response should be defined in the Prepare tab of your inline_javascript item
    2. There's a typo in line 25 of this script (vars.correct.response should be vars.correct_response)
    3. Feedback ("Goed" or "Fout") should be shown by using a feedback item rather than a sketchpad item. See also here: https://osdoc.cogsci.nl/3.3/manual/stimuli/visual/#the-difference-between-sketchpad-and-feedback-items

    I attached an updated script. I only looked at the first practice round.


    Hope this helps!


    Cheers,


    Lotje


    Did you like my answer? Feel free to Buy Me A Coffee :)

  • Awesome! Thanks so much @JasperdeWaard and @lvanderlinden for responding so quickly and for taking the time to adjust my script. Everything seems to be running as it should now :)

  • Great to hear! :)

    Did you like my answer? Feel free to 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