Howdy, Stranger!

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

Supported by

[solved] Correct usage of "Break if" field in a loop item

edited March 2015 in OpenSesame

I'm trying to quit a practice block after 5 trials and then continue with the real experiment. I entered the following value in the "Break if" field in the hopes this would happen:

[count_trial_sequence] > 4 and [practice] = "yes"

I also had to manually set "count_trial_sequence" to 0 in a script item before entering the loop. Otherwise, OS would crash saying that this variable doesn't exist, probably because it hasn't entered the trial_sequence yet the first time the loop is run.

However, the practice block just keeps running! If I only enter

[count_trial_sequence] > 4

it does work (and the practice block only runs for 5 trials). However, OS also does not enter the experimental blocks anymore, because the count_trial_sequence value keeps incrementing, causing the "break if" statement to always be true in the experimental blocks. Hence I need to also check for [practice] = "yes".

What is the best way to approach this problem and only break out of the practice loop item after 5 trials? Thanks!

Buy Me A Coffee

Comments

  • edited 1:11AM

    I found the solution myself.
    OpenSesame doesn't like the quotes around the value "yes", but doesn't give a notice that this is wrong and simply regards the break_if field as empty

    so if I replace

    [count_trial_sequence] > 4 and [practice] = "yes"
    

    with

    [count_trial_sequence] > 4 and [practice] = yes
    

    everything works as expected!

    Buy Me A Coffee

  • edited 1:11AM

    Hi Daniel,

    Thanks for spotting this one. This behavior is of course incorrect and I opened an issue for it:

    Cheers!
    Sebastiaan

    Buy Me A Coffee

  • edited 1:11AM

    Hello Sebastiaan,

    I am very new to programming and I am sorry to ask a maybe very simple question:
    In the LOOP function we have advanced options and a field called "break, if".
    I simply would like to break the loop and show the next "End of experiment" text when pressing SPACE.

    How would I do that? Something like: keypress SPACE = true ??

    I hope you can help me with this,
    Thanks,

    Ka

  • edited 1:11AM

    Hi Ka,

    First off, you would need to have keyboard_response item somewhere below the loop, for example in the sequence that is the item-to-run for the loop. Then you can simply use the following break-if statement: [response] = space.

    See also:

    The break-if statement is evaluated before the loop's first cycle. So to avoid the loop from complaining that the variable response is not known, and to avoid the loop from not executing any cycles at all, you can reset the response variable just before the loop, with a simple inline_script:

    exp.set('response', 'None') 
    

    Cheers!
    Sebastiaan

    Buy Me A Coffee

  • edited 1:11AM

    Hey Sebastiaan,

    I have a similar question to the previous questions on this thread. Specifically, in my study I am having participants complete a task that involves naming the 50 United States (or as many as they can). To accomplish this, I have a loop repeating a sequence 50 times and the sequence contains a text_input item and a logger item - and this works well.

    However, once students are no longer able to name any additional states, I'd like to have the program recognize the entry 'na' and then break out of the loop and move onto the next task. I've attempted to do this using the "Break if" option in the loop (i.e., set break_if "[response] = 'na'") but it tells me that it doesn't recognize the response variable at the start of the loop. I've tried to use the exp.set('response', 'None') method you described previously, but that didn't help either. I'm sure there is a way to do this but I haven't been able to find it in the forums, any guidance you can provide would be very helpful!

    Thanks,

    Anthony

  • edited 1:11AM

    Hi Anthony,

    I tried Sebastiaan's suggestions myself and it seems to work. Under this link here you can find a minimal example, that might be enough for you, to get an idea, what is going wrong.

    Please let us know, if it doesn't help.

    Good luck,

    Eduard

    Buy Me A Coffee

  • edited 1:11AM

    Hi Anthony,

    The problem here is that the break_if command may seem to work a bit differently than regular python code. Your line of code, set break_if "[response] = 'na'", needs to be changed into: set break_if "[response] = na", i.e., without the quotation marks around 'na'.

    In the loop item, in the 'View controls' window rather than the 'View script' window, you can check the "Show advanced options" box and simply insert [response] = na (without quotation marks) behind 'break if'.

    Let me know if this works!

    Cheers,
    Josh

  • edited 1:11AM

    Hey Josh and Eduard,

    Thanks for your responses. Turns out it was an ID-10-T (user) error on my part, but your responses did help me realize that.

    Thanks again!

    Anthony

  • edited 1:11AM

    @ACoy Now that's a joke I haven't seen in a looooong time!

  • edited 1:11AM

    Hi,
    I'm new to programming, and i have the same problem. I wrote : [count_trial_sequence] > 4 and [practice] = yes , and thought to reset the trial counter to 0 in a inline script.
    But when i try to run a quick view of the experiment, they tell me that the variable [practice] doesn't exist....

    Can you help me ?

    Thank you,

    chloé

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