Howdy, Stranger!

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

Supported by

[solved] Eliminating a sequence

edited March 2013 in OpenSesame

Hi Sebastiaan,

Thank you for your Opensesame software! Is there a way to eliminate the highlighted "trial_sequence" category so that my smaller sequences (4 of them are shown below) are under the "Bigloop"? My goal is to randomize the smaller sequence chunks, but they are currently going in order.

image

Thank you!

Comments

  • edited March 2013

    Hi,

    Welcome to the forum!

    Is there a way to eliminate the highlighted "trial_sequence" category so that my smaller sequences (4 of them are shown below) are under the "Bigloop"?

    No, a loop item can only be wrapped around one sequence item. And a sequence item can only run it's content in sequence.

    What you could do to run your four small sequence items in random rather than sequential order is the following:

    • Open your trial_sequence item and set the "Run if" statements of the four small sequences to 'never'.
    • Append an inline_script item to your trial_sequence item (make sure to place it at the beginning).
    • Put the following piece of Python inline code to the Prepare phase tab of the inline_script item (see comments for further explanation):
    import random
    
    # Make a list containing the four names of the small sequence items:
    l = ['s1', 's2', 's3', 's4']
    
    # Randomise the list by using the random.shuffle() function:
    random.shuffle(l)
    
    # Walk through the (randomised) list:
    for sequence in l:
    
        # Prepare the sequence item:
        exp.items[sequence].prepare()
    
        # Run the sequence item:
        exp.items[sequence].run()
    

    An example experiment can be downloaded here (save with the extension .opensesame)

    I hope this helps!

    Best,

    Lotje

  • edited 4:29AM

    Dear Lotje,

    Thank you so much for your help! I am not quite there yet...did I misspell some things? My small sequences are called "small1...small8" so I renamed them:

    image

    image

  • edited 4:29AM

    You wrote for sequence in 1, while the correct code is for sequence in l, where l is the name of the list containing the sequence names (in your case 'small1', 'small2' etc.).

    Cheers,

    Andrea

  • edited 4:29AM

    Andrea,

    Thank you for your help! I tried to replace the 1 with the 'small1', 'small2,' etc. but I am not sure why it still doesn't work? I also tried typing in exp.items['small1', 'small2,' etc].prepare() but it didn't work either. Sorry for taking a while to figure this out...

    image

  • edited 4:29AM

    Hi,

    What Andrea meant is that you accidentally changed the 'l' in the for statement to '1'. And in your most recent post, you named the list '1' instead of 'l'.

    The code should be as follows. For the sake of clarity, I renamed the list to 'sequence_list' instead of 'l':

    # Make a list containing the four names of the small sequence items:
    sequence_list = ['s1', 's2', 's3', 's4']
    
    # Randomise the list by using the random.shuffle() function:
    random.shuffle(sequence_list)
    
    # Walk through the (randomised) list:
    for sequence in sequence_list:
    
        # Prepare the sequence item:
        exp.items[sequence].prepare()
    
        # Run the sequence item:
        exp.items[sequence].run()
    

    I also uploaded an example experiment (see the link in my first post) at which you could take a look if you want.

    Does this answer your question?

    Best,

    Lotje

  • edited March 2013

    For simplicity, try to copy and paste the code originally posted by Lotje, and you will see that it will work. Perhaps, you are confounding 1 (number) with l (letter). Basically, l is the name of the list containing the various sequences (l = ['small1', 'small2', 'small3', 'small4', 'small5', 'small6', 'small7', 'small8']). Then, you shuffle this list (random.shuffle(l)) and run each list element, that is each sequence (for sequence in l).

    In any way, if you copy and paste the Lotje's code, it will works.

    Hope this helps.

    Edit: Lotje and I posted at the same time. Lotje's answer should clarify your doubts

  • edited 4:29AM

    Thank you so much, Lotje and Andrea! It finally works =)

Sign In or Register to comment.