Howdy, Stranger!

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

Supported by

[open] Esay way off adding file pool items as variables?

edited January 2015 in OpenSesame

I couldn't find anything regarding this in the various help sections and tutorials.

So I have around 300 soundfiles in my file pool, and want to add then to a variable in my loop. Is there an easy way to copy/paste the sound file names into the variable? Or do I have to hand-type them all?

Comments

  • edited 2:06AM

    Hi,

    The folder that contains the file pool is available as exp.pool_folder, so you can get a list of all files in the pool like this (randomly shuffled):

    # Retrieve all files in the pool folder as a list
    import os
    import random
    fname_list = os.listdir(exp.pool_folder)
    # Randomly shuffle the list
    random.shuffle(fname_list)
    

    Then, at the beginning of each trial, you could get one item from this list and use it as an experimental variable, like so (in the prepare phase of an inline_script):

    # Pop the last file name from the list and set it as experimental variable
    # `fname`
    exp.set('fname', fname_list.pop())
    

    Does that help at all?

    Cheers,
    Sebastiaan

  • edited 2:06AM

    Well, I am not the best at coding within Open Sesame (I only followed an introductory course)
    I do however, get what the script is trying to do. My question is just: Where in the experiment do I place the first part of the script (where it retrieves a file list)? if I place it in an in-line script before the loop sequence (the actual experiment) starts, it says fname_list stays undefined When it tries to run the prepare phase of the second script.

    If this takes too much time to properly explain, i will just do it by hand. It would take it bit longer, but at least I know how that works ;)

    Thanks for the help anyway!

  • edited 2:06AM

    Just at the very begging of the experiment in the prepare phase of an inline_script item should do the trick!

Sign In or Register to comment.