Howdy, Stranger!

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

Supported by

[solved] breaking out of loop after 1 stimulus

edited April 2014 in OpenSesame

have tried a few things. tried using the Count variable and then used Break if = count_seq >1 in the loop object. I thought this would work.. Must i make a new variable in an inline script which matches the count variable? and then use this in my Break If line instead of directly calling the count variable? i.e.

Count1 = self.experiment.get('count_Cue_seq')

then in Break if = Count1>1

:( struggling here

Comments

  • edited April 2014

    Referring to variables is done using square brackets, like so for you break if statement:

    [count_seq] > 0
    

    EDIT: count needs to exceed 0, as Python starts counting at zero (thus the first trial is numbered trial 0).

    Also, you might need to add an inline script to the very start of your experiment, and place this in the Prepare phase:

    exp.set("count_seq", 0)
    

    This will make sure that the variable that you use in your loop (i.e. count_seq already exists when the loop is being prepared. Otherwise the variable will be defined only upon running the sequence, which happens after preparation of the loop. Therefore, the variable you reference in your break if statement will not exists yet, and that would result in an error.

  • edited 8:01AM

    Thanks for this. This is working.. however it shows 2 stimuli and then breaks, not just 1.

  • edited 8:01AM

    ok i did it as break if [count_seq] >0

    for the first time around, it displays 2 stimuli then breaks but then on the second time round and for all times after, it works as it should and just displays 1. weird

  • edited 8:01AM

    Python (and thus OpenSesame) starts counting at zero, so your first stimulus will be counted as presentation 0 rather than 1. Glad that it's solved! :)

  • edited 8:01AM

    Its not completely solved as it is still displaying 2 stimuli in the first loop. Then acts as expected after this by only showing 1. I cant understand how this can be? all counts start at 0 and Break if >0. No idea why it does this. would this be a bug?

    Many thanks

  • edited April 2014

    The behaviour kind of depends on what variable you are using as a counter, and how this variable is influenced by the stimuli in your loop. Could you perhaps post an overview and/or a script of the experiment?

  • edited 8:01AM

    the experiment basically presents a cue (a lowercase letter), then an empty 3x3 grid, then a 3x3 grid with an X marked in one of the cells. The task is to imagine the uppercase version of the cue and to mentally project this onto the empty grid. When the marked grid appears, you respond as to whether the mark would fall on top of your imagined letter (with a keypress of X for yes or N for no).

  • edited 8:01AM

    I tried to post the code into here but did not post. Please see dropbox link below

    https://www.dropbox.com/s/pfj7shgyxthm09i/Imagine_example.opensesame.tar.gz

  • edited 8:01AM

    Have you uploaded the correct version? There are no Break if statements in the loops of the version that you have uploaded.

  • edited 8:01AM

    I can see that, not sure why it has removed from that field, it is still there though, in the main script of the experiment. ive re-inserted the code in the field just to make sure and it still behaves the same

  • edited 8:01AM

    any thoughts guys?

  • edited 8:01AM

    So the counting does not quite happen as I thought it would. Easy solution is to introduce our own counter using three inline_script items.

    Place this into the inline_script you currently have at the start of your experiment ("set_count"):

    exp.set("counter", 0)
    

    Place the following within the Cue_seq sequence:

    exp.set("counter", exp.get("counter")+1)
    

    Finally, place this at the end of the MasterSeq sequence (in the inline_script called "resetting"):

    exp.set("counter", 0)
    

    Now, your CueLoop's Break if statement should be counter > 0

  • edited 8:01AM

    thanks so much, Edwin.

  • edited April 2016

    Hi guys,

    I try to break out of the practice loop after 2 trials.
    I added the inline script at the start of the experiment, in the prepare phase, and entered the break-if statement in my practice loop juste like you did.
    But it still doesn't work, and the practice block keeps running.

    I tried with only [count_trial_sequence] > 2 , then "2" , then followed by "and [practice] = yes" , "yes"...
    When i add [practice] = yes in the break if statement in the practice loop, i also add exp.set("practice", yes) in the inline script.
    Nothing works.
    It keeps running.
    Please help...

    Many thanks

Sign In or Register to comment.