[solved] Correct usage of "Break if" field in a loop item
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!


Comments
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
with
everything works as expected!
Hi Daniel,
Thanks for spotting this one. This behavior is of course incorrect and I opened an issue for it:
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
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
Hi Ka,
First off, you would need to have
keyboard_responseitem somewhere below theloop, for example in thesequencethat is the item-to-run for theloop. 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 theloopfrom complaining that the variableresponseis not known, and to avoid theloopfrom not executing any cycles at all, you can reset theresponsevariable just before the loop, with a simpleinline_script:Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
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
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
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
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
@ACoy Now that's a joke I haven't seen in a looooong time!
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é