Howdy, Stranger!

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

Supported by

[open] Pseudorandom order, items in sequence?

edited June 2015 in OpenSesame

So, I'm a complete newbie to experimental design. I was a philosopher by training that needed to start testing my ideas. I did the beginner's tutorial, and now I want to use OpenSesasme to implement a replication experiment.

The basic gist of the experiment is this.

I present a word on screen via sketchpad.

Next, I present an image on the screen via sketchpad in quadrant 2. This image stays put through the rest of the trial.

Next, I present an image on the screen via sketchpad bisecting the mid-line of the graph in quadrant 2 and 1. This image stays put through the rest of the trial.

Next, I present an image on the screen via sketchpad in quadrant I. This image stays put through the rest of the trial.

Then, the participant has a choice.

I simultaneously present in quadrant 3 and quadrant 4 two images. They need to select the image that corresponds to the series that they I just presented.

So, the logic of the design is:

If A, then necessarily B, and if B, then necessarily C, and if C, then either D and E or E and D.

Note the last consequence "either D and E or E and D" corresponds to the idea that either the target is on the left and the distractor is on the right, or vice versa.

The way that I currently have this experiment set up seems wrong.

I have the main experiment sequence, and nested right under that I have the instructions. Then, I have a single loop. Set inside that loop there is a sequence0. And then, I have 11 more sequences.

What I need to happen
The words presented pseudorandomly. I don't want the participant to see the same word twice.

The target and distractor to be randomly assigned to the left or right.

Is there any tutorial that would help me with this?

Also, I wanted to record audio during the entire experiment, but it seems that the audio input doesn't work for MAC yosemite 10.10. Any idea what's going on with that? I can post more details as soon as someone indicates they might be willing to help.


  • edited 3:20AM

    Hi Dani,

    Cool experiment with the logic and everything - but if I understand you well the only thing you need to know is how to pick and assign things randomly?
    I think the easiest way is to place an inline_script item inside the loop before the series of sketchpads. In this inline_script you can define your variables, i.e. words and target/distractor locations, each trial. At the top of the script you can insert: from math import random. This will make some useful functions available.

    Now to pick a random word that can't be picked twice, you'll have to make a list of all words, e.g. wordlist = ['boat', 'lion', 'mule', 'spot']. You shuffle this list with the command: random.shuffle(wordlist).
    Next, you pick an item, removing it from the list so it can't be picked twice: word = wordlist.pop(0).
    Your word, (contained in a variable named 'word'), is only available/callable in an inline_script. To make it available for your sketchpad, you have to insert: exp.set('word',word). In the sketchpad, inserting '[word]' on your desired location (without apostrophes, but with parentheses) will display whichever word was picked.

    Assigning a random location for target and distractor will work in a fairly similar way. You have a list with the target and distractor (e.g. list = ['target.png', 'distractor.png']), which you randomly shuffle, and then just select the two locations for:

       left = list.pop(0)  # picks the first from two elements.
       right = list.pop(0)  # picks the first from one element.

    In your next sketchpad, you can insert [left] in the left corner, and [right] in the right corner.
    Do make sure that you have a means to process the response as well. For instance:

       if left == 'target.png':
              correct_response = 'z'
              correct_response = 'm' #(depending on which buttons you want to use)

    The keyboard response item will then automatically log whether the given response was correct or not.

    Good luck!


  • edited 3:20AM

    I tried a bit of what you wrote, but I'm afraid I was not clear enough, and my skills are mediocre at best.

    So, let me try again.

    In my OpenSesame, a sequence consists of 4 sketchpads, a keyboard response item, and a logger.

    1st - present a word
    2nd - present the first image of the series
    3rd - present the first and second image of a series
    4th - present the first, second, and third of a series
    5th - present two options for the participant - corresponds to the question, which images comes next?

    I want the first sketchpad to draw and present one word from a wordlist without replacing that word back in the deck of cards, so to speak.

    The next three sketchpads are defined by me because they define the beginning of the series. So, I don't think I need to screw with them.

    However, I want the last sketchpad to do this: if the target is on the left, then the distractor should be on the right. But, the trick is this.....these targets and distractors are completely unique to this particular sequence. No other sequence in my OpenSesame will utilize these exactly images.

    I've tried several things, including, creating a loop for each sequence, but this doesn't seem to do the trick. If I introduce the wordlist into the variable wizard, then the variable wizard wants me to run the loop for as many cycles as there are words in my list.

    To put the icing on the cake, I have 12 sequences and I want the sequences to be random.

    :( Please help

  • edited June 2015

    Welcome to experimental design :D

    Let's start with the icing on your cake: you have 12 sequences, but what are they for? Should they represent 12 trials? Or 12 trial types? Either way, I think you should be able to work with just one sequence. How many trials and how many types you're going to end up with can be defined in a single loop item.

    The things I suggested in my previous comment are mostly still applicable here. For instance, you want a unique pair of target and distractor for every sequence (=trial?). Well, just make a list of target/distractor pairs in much the same way as the other things, e.g.: targetdistractor_pairs = [["target1","distractor1"], ["target2","distractor2"]] etc. (As you can see, you'd have a list, consisting of tiny lists). Again you randomly shuffle and pop; and then to decide left and right you do the very same thing, like I suggested previously.

    Really the central point is to define all your stimuli, words, images, target/distractor locations at the beginning of each trial - that is, the beginning of each iteration through your loop. Normally alot of those variables can be defined with the loop item itself; for instance the variable wizard like you mentioned. However, if you just want everything to be random you might as well just indicate the amount of cycles in your loop item (which will ultimately equal the amount of trials) and not use the wizard.

    Your goal is to assign values to all objects in your trial. If a line in my inline_script says "word = random.shuffle(["fish", "dish"]).pop(0)", for instance, I will end up with a variable named 'word' that contains the value "fish" or "dish". Placing [word] in a sketchpad will display "fish" or "dish", simple as that. Want to use 15 sketchpads that stack multiple words or images? Fine - in the first sketchpad you place the [word], in the second one you place [word] [image1], in the third you place [word] [image1] [image2], etc.

    I suggest you place a single inline_script in front of (so not inside) the loop item, and define all lists there. A word list, a list of possible target distractor pairs, a list of all image sequences and so forth.
    Inside the loop item you begin with another inline script - and in this one, you simply pick an item from each of the lists. The .pop(0) command makes sure that you'll only use an item from a list once!

    If anything is unclear to you, feel free to ask; but I'd also suggest spending a google or two on lists, random and python.



  • edited 3:20AM


    I'm familiar with lists. Python, I'm still working through the code-acad tutorial. And random, I get that it's a function that I can use on items in a list, i.e. random(words) You say to make a list for my words. Ok, I did that. I also made a list of the image pairs: a list of tiny lists.

    But, it's not at all clear what you're suggesting anymore.

    I tried inserting the inline script before the loop, and writing:

    from math import random
    wordlist = ["dog", "cat", "snake", "fox"]
    word = wordlist.pop(0)

    And then I tried using


    in my sketchpad,
    but when I run the experiment, it says I don't have [word] defined.

    I also tried putting the following in an inline before the loop:

    from math import random
    wordlist = ["dog", "cat", "snake", "fox"]

    and in an inline script in the loop placing:

    word = wordlist.pop(0)

    But, that didn't work either.

    Again, the basic idea of the experiment is like this....

    1. "Things in the kitchen"
      A B C
      D E

    2.  "Public Holidays"
               1 2 3 
                 4 5 
    3.        "Crimes"
       Big bigger biggest 
            Smaller Small 

    The top row corresponds to the word, the second row corresponds to a set series of images, and the bottom row corresponds to a choice that the participant has to make regarding what is the correct continuation of the proceeding row.

    As you can see, what I had was a bunch of sequences, but I ran into the problem that
    a) I want to run through each sequence once
    b) I want the words that were to be presented on the first sketchpad shuffled
    c) I couldn't shuffle the order of the entire sequence presentations, i.e. sequence3, sequence0, sequence1
    d) I can't figure out how to make it so that the final two images are presented either on the left or the right.

    What do you think? Should I redo the simple tutorial? I feel like it left me asking more questions, and gave me a false sense of security. :( Python be damned!

  • edited 3:20AM

    Hi Dani,

    I'm by no means an expert in Python but let me try to help as a way to learn some things myself as well.

    First of all, i think you are trying to create too many sequences. Every trial you want to present has the same procedure so you can merge all into one. In the loop that precedes it you can define six different variables:

    • Theme (example: "Public holidays")
    • Picture 1
    • Picture 2
    • Picture 3
    • Target picture
    • Distractor picture

    and fill them with the word and picture pairs you want to use so that every row has a unique set of stimuli. In the loop item you can select how many times you want to cylce through this list (12 in your case), set the order (random) and amount of repeatings (1).

    As for the target and distraction locations you could try to select a random number at the beginning of the sequence and appoint the target location and correct keyboard answer accordingly:

    exp.set('rand', [])
    import random
    # Select random number between 0 and 1
    rand = random.randint(0,1)
    print rand
    # Target on left side
    if exp.get('rand') == 0 :
        exp.set('target_loc', -384)
        exp.set('distractor_loc', 384)
        exp.set('correct_response', 'z')
    # Target on right side
        exp.set('target_loc', 384)
        exp.set('distractor_loc', -384)
        exp.set('correct_response', 'm')

    And alter your script in the final sketchpad like this:

    draw textline "[target_loc]" 0 "[Target]" ...
    draw textline "[distractor_loc]" 0 "[Distractor]" ...

    But again, i'm no experienced builder myself and i have not tested this little script so if anyone has a more elegant solution please correct me!

  • edited 3:20AM

    Knante said, "fill [the variables in the loop] with the word and picture pairs you want to use so that every row has a unique set of stimuli".

    I don't know what he meant by word and picture pairs.

  • edited 3:20AM

    And what's up with all the crashing on for mac version of openSesame? It crashes all the time.

  • edited June 2015

    This is what i mean, i used just words in the example but you can substitute them with pictures:


  • edited 3:20AM

    Hi Dani,

    You were almost there. If you look at my first post, you can see: "To make it available for your sketchpad, you have to insert: exp.set('word',word)."

    So yeah, you created the variables in your inline script perfectly, now you only need to set them with exp.set, and you can do whatever you want with them in your sketchpads!



  • edited 3:20AM

    A few questions:

    Where do I insert "exp.set('word',word)"? In the prepare or run part of the in-line script?


    How do I get items underneath the in_line script? When I insert the in-line script into my loop item, it doesn't allow for any other items to be placed under it? From the picture, you should be able to see that sketchpad items are "under" the in_line script, but not "under" loop and not "under" the in_line script in the relevant sense.

    Also, here's a look at my lists, which you told me to make. I'm not sure if this is what you had in mind.

    words = [“Tiere”, “Städte”, “Obst”, “Filme”, “Autoren”, “Musikinstrumente”, “Länder”, “Feiertage”, “Spiele “, “Spielzeug”, “Mädchen Namen”, “Filmgrößen”, “Farben“, “Körperteil”, “Wissenschaftsfächer”, “Fächer “, “Universitäten”, “Rauschgift”, “Verbrechen”, “Beruf”, “Büro“, “Elektronikgeräte”, “Fortbewegungsmittel”, “Gemüse”, “Insekten”, “Kleidung”, “Lebensmittel”, “Möbel”, “Krankheiten”]

    sequence_1 = [“1.png”, “2.png”, “3.png”, “4.png”, “w.png”]
    sequence_1_target_distractor = [“4.png”, “w.png”]

    sequence_2 = [“1a.png”, “2a.png”, “3a.png”, “4a.png”, “wa.png”]
    sequence_2_target_distractor = [“4a.png”, “wa.png”]

    sequence_3 = [“1b.png”, “2b.png”, “3b.png”, “4b.png”, “wb.png”]
    sequence_3_target_distractor = [“4b.png”, “wb.png”]

    sequence_4 = [“1c.png”, “2c.png”, “3c.png”, “4c.png”, “wc.png”]
    sequence_4_target_distractor = [“4c.png”, “wc.png”]

    sequence_5 = [“1d.png”, “2d.png”, “3d.png”, “4d.png”, “wd.png”]
    sequence_5_target_distractor = [“4d.png”, “wd.png”]

    sequence_6 = [“1e.png”, “2e.png”, “3e.png”, “4e.png”, “we.png”]
    sequence_6_target_distractor = [“4e.png”, “we.png”]

    sequence_7 = [“1f.png”, “2f.png”, “3f.png”, “4f.png”, “wf.png”]
    sequence_7_target_distractor = [“4f.png”, “wf.png”]

    sequence_8 = [“1g.png”, “2g.png”, “3g.png”, “4g.png”, “wg.png”]
    sequence_8_target_distractor = [“4g.png”, “wg.png”]

    sequence_9 = [“1h.png”, “2h.png”, “3h.png”, “4h.png”, “wh.png”]
    sequence_9_target_distractor = [“4h.png”, “wh.png”]

    sequence_10 = [“1i.png”, “2i.png”, “3i.png”, “4i.png”, “wi.png”]
    sequence_10_target_distractor = [“4i.png”, “wi.png”]

    sequence_11 = [“1j.png”, “2j.png”, “3j.png”, “4j.png”, “wj.png”]
    sequence_11_target_distractor = [“4j.png”, “wj.png”]

    sequence_12 = [“1k.png”, “2k.png”, “3k.png”, “4k.png”, “wk.png”]
    sequence_12_target_distractor = [“4k.png”, “wk.png”]

    Thanks for helping!

  • edited 3:20AM

    Hi Dani,

    Yeah, this is perhaps a bit counter-intuitive: the loop item can indeed only loop one item. In order to loop more, you'll have to place a sequence item in the loop, and place your inline_script and everything else in the sequence item.
    The exp.set command can be put in the prepare phase, right after you declared your variable.

    Good luck!


  • edited 3:20AM

    Where do I insert "exp.set('word',word)"? In the prepare or run part of the in-line script?

  • edited 3:20AM

    Sorry, I didn't read what you wrote carefully. You said in the prepare phase.

  • edited June 2015

    Hey Josh! Your help has been amazing. I finally have made some progress.

    But, I have a problem. I don't know what I'm doing wrong here.

    Just to reiterate what I think I want and how it relates to open-sesame:

    We have twelve trials, that is, participants make 12 independent decisions.

    Before each decision, we present an order series of stimuli.

    Now, let's get more specific.

    At the very start of trial, we present a randomly selected word from a list and present this word to participants. We do this by calling the variable [word] that we set in our in_line script at the start of the sequence item within our loop.

    #-------------------------------BEGINS MY IN_LINE SCRIPT---------------------
    import random 
    wordlist = ["Tiere", "Städte", "Obst", "Filme", "Autoren", "Musikinstrumente", "Länder", "Feiertage", "Spiele", "Spielzeug", "Mädchen Namen", "Filmgrößen", "Farben", "Körperteil", "Wissenschaftsfächer", "Fächer", "Universitäten", "Rauschgift", "Verbrechen", "Beruf", "Büro", "Elektronikgeräte", "Forbewungsmittel", "Gemüse", "Insekten", "Kleidung", "Lebensmittel", "Möbel", "Krankheiten", "Gefühle", "Werkzeuge", "Bücher", "Jungennamen", "Sänger"]
    word = wordlist.pop(0)

    The next sketchpad presents an image. we also want this image to be randomly selected from a list. So, the same way that we presented the word, we present the image.

    #-----------------------------SETTING MY FIRST IMAGE LIST--------------------
    first_image = ['1.png', '1a.png', '1b.png']
    first_image_pop = first_image(0)
    exp.set('first_image_pop', first_image_pop) 

    On the next sketchpad, we want to present the image that corresponds to the last image that we just randomly called. This is a bit tricky because I need the second, third, fourth, and fifth images to be the right images, the images that correspond to the first one that I selected with random.shuffle(). I'm having problems here. Here is what tried.

    #-------------------------------BEGIN DEFS OF SECOND & THIRD IMAGES---------
    second_image = ['2.png','2a.png','2b.png']
    exp.set('second_image', second_image)
    third_image = ['3.png', '3a.png', '3b.png']
    exp.set('third_image', third_image)
    if first_image_pop == '1.png': #If I got 1.png on random.shuffle(first_image), then...
        second_image == "[second_image[0]]" #the second image should be the file indexed #by position o in the second_image list 
        third_image == "[third_image[0]]" #the third image should be the file indexed #by position o in the third_image list 
    if first_image_pop == '1a.png':
        second_image == "[second_image[1]]"
        third_image == "[third_image[1]]"
    if first_image_pop == '1b.png':
        second_image == "[second_image[2]]"
        third_image == "[third_image[2]]"

    The above doesn't work, though. The error messages tells me I can't call lists. Any idea what went wrong?

    Also, below is my way of dealing with the fourth and fifth images, the images that correspond to the choice participants need to make. I'm not sure how I can get those into the mix above. Any suggestions?

    #-------------------------------HERE BEGINS THE FOURTH & FIFTH IMAGES RANDOMS
    TD_pair_one = ['4.png', 'w.png']
    left = TD_pair_one.pop(0)  # picks the first from two elements.
    right = TD_pair_one.pop(0)  # picks the first from one element.
    if left == '4.png':
        correct_response = 'z'
        correct_response = 'm' #(depending on which buttons you want to use)
    TD_pair_two = ['4a.png', 'wa.png']
    lefta = TD_pair_two.pop(0)  # picks the first from two elements.
    righta = TD_pair_two.pop(0)  # picks the first from one element.
    if lefta == '4a.png':
        correct_response = 'z'
        correct_response = 'm' #(depending on which buttons you want to use)
    TD_pair_three = ['4b.png', 'wb.png']
    leftb = TD_pair_three.pop(0)  # picks the first from two elements.
    rightb = TD_pair_three.pop(0)  # picks the first from one element.
    if left == '4b.png':
        correct_response = 'z'
        correct_response = 'm' #(depending on which buttons you want to use)

    p.s. Josh, thanks again. please let me buy you a beer or two.

  • edited 3:20AM

    Glad to help!

    I think I understand the logic - the first image is selected at random, and then the second and third picture should be in accordance with the first image.

    The problems you're currently facing are due to syntax. If you want the first element from your second_image list, you can write this:

      second_image = second_image[0]

    So, the double equals sign is only used in logical arguments (such as if-statements); the single equals sign is used to let a variable become a value. Further you shouldn't put the value on the right side of the equation between quotation marks, unless you want it to become a string that literally says "second_image[0]". And also note that after the above statement, the variable second_image has become the first element of the list - which means that second_image is actually not a list anymore (and subsequently, second_image[2] wouldn't work anymore).

    Since the second and third image always depend on the first image pick, you could also make triplets of images:

      images = [["1.png", "2.png", "3.png"], ["1a.png", "2a.png", "3a.png"], ["1b.png", "2b.png", "3b.png"]].
      image_pop = images.pop(0)
      first = image_pop[0]
      second = image_pop[1]
      third = image_pop[2]
      exp.set('first', first)
      exp.set('second', second)
      exp.set('third', third)

    Hope this helps!



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 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