Howdy, Stranger!

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

Supported by

[Solved] Recording randomized order and using it later for presentation

edited March 2012 in OpenSesame

Hi Sebastiaan!

I have another randomization question. I have created a loop which plays a set of 12 items presented in random order. Each of those 12 has one corresponding item. What I need to do is to record somehow the order of the presentation to later be able to:

a) present all 12 corresponding items in another loop in the exact same order as the original items were presented,
b) present first 9 corresponding items in new random order; then present the remaining 3 items (also in random order)

The point is to present 12 faces with names (and some other stuff) so that the subject can memorize them and consequently present faces without names so that the subject can recall the name. However, I want to avoid a situation where for instance the last three items presented for memorizing were presented first in the recall phase as this could affect the performance of the subject.

How do I proceed?

Thanks!

EDIT: Option a) (preferred) has been solved = recording randomized order and then recalling it (even repeatedly).

Comments

  • edited March 2012

    I think I can answer that for you as well:

    In it's most simple form, the experiment would look like this:

    sequence_experiment (basic sequence, i.e. whole experiment)

    ...inline_script_1 *

    ...sketchpad_welcome (introduction)

    ...loop_items (this is where you add a variable for the 12 items, in this example "number")

    ......sequence_items (plays for every one of the twelve items)

    .........sketchpad_items (display item)

    .........inline_script_2 **

    .........logger_item (to log data of choice)

    ...loop_corresponding (just add twelve cycles, no variables needed!)

    ......sequence_corresponding

    .........inline_script_3 ***

    .........sketchpad_corresponding (to display corresponding item, using [stim] - a variable defined in inline_script_3, see below)

    .........logger_corresponding (log data of choice

    inline_script_1, RUN phase
    global stimage
    stimage = [] # define empty list

    inline_script_2, RUN phase
    global stimage
    stimage.append(self.get("number")) # add number of displayed item to list

    inline_script_3, PREPARE phase
    global stimage
    stim = stimage[self.get("count_inline_script_3")] # set local variable 'stim', to be used in sketchpad_corresponding,
    self.experiment.set("stim",stim) # set it so that OpenSesame will be able to use it

    If that's still a bit unclear, here's the code for a sample experiment I just build, showing the same row of numbers (1 to 5 in random order) twice:

    set foreground "white"
    set subject_parity "even"
    set description "Default description"
    set title "New experiment"
    set sampler_backend "legacy"
    set coordinates "relative"
    set height "768"
    set mouse_backend "legacy"
    set width "1024"
    set compensation "0"
    set keyboard_backend "legacy"
    set background "black"
    set subject_nr "0"
    set canvas_backend "legacy"
    set start "experiment"
    set synth_backend "legacy"

    define loop loop_corresponding
    set repeat "1"
    set description "Repeatedly runs another item"
    set item "_sequence"
    set column_order ""
    set cycles "5"
    set order "random"
    run sequence_corresponding

    define logger logger_item
    set ignore_missing "yes"
    set description "Logs experimental data"
    set auto_log "yes"

    define sequence experiment
    set flush_keyboard "yes"
    set description "Runs a number of items in sequence"
    run inline_script_1 "always"
    run welcome "always"
    run loop_item "always"
    run loop_corresponding "always"

    define sketchpad welcome
    set duration "keypress"
    set start_response_interval "no"
    set description "Displays stimuli"
    draw textline 0 0 "OpenSesame 0.25 'Dashy Darwin'" center=1 color=white font_family=serif font_size=32 show_if="always"

    define inline_script inline_script_1
    _run
    global stimage
    stimage = []
    end
    set _prepare ""
    set description "Executes Python code"

    define inline_script inline_script_3
    set _run ""
    ___prepare__
    global stimage
    stim = stimage[self.get("count_inline_script_3")]
    self.experiment.set("stim",stim)
    end
    set description "Executes Python code"

    define inline_script inline_script_2
    _run
    global stimage
    stimage.append(self.get("number"))
    end
    set _prepare ""
    set description "Executes Python code"

    define sequence sequence_corresponding
    set flush_keyboard "yes"
    set description "Runs a number of items in sequence"
    run inline_script_3 "always"
    run sketchpad_corresponding "always"
    run logger_corresponding "always"

    define sketchpad sketchpad_corresponding
    set duration "keypress"
    set description "Displays stimuli"
    set start_response_interval "no"
    draw textline 0 0 "[stim]" center=1 color=white font_family=mono font_size=18 show_if="always"

    define logger logger_corresponding
    set ignore_missing "yes"
    set description "Logs experimental data"
    set auto_log "yes"

    define sequence sequence_item
    set flush_keyboard "yes"
    set description "Runs a number of items in sequence"
    run sketchpad_item "always"
    run inline_script_2 "always"
    run logger_item "always"

    define loop loop_item
    set repeat "1"
    set description "Repeatedly runs another item"
    set item "sequence"
    set column_order "number"
    set cycles "5"
    set order "random"
    setcycle 0 number "1"
    setcycle 1 number "2"
    setcycle 2 number "3"
    setcycle 3 number "4"
    setcycle 4 number "5"
    run sequence_item

    define sketchpad sketchpad_item
    set duration "keypress"
    set description "Displays stimuli"
    set start_response_interval "no"
    draw textline 0 0 "[number]" center=1 color=white font_family=mono font_size=18 show_if="always"

    Hope this helps!
    Edwin

  • edited 5:19AM

    Thanks for your reply, Edwin!

    Well, I have never used an inline_script item before so I look forward to learn something new (when I can get to it - today we are on strike). I'll keep you posted.

    Jakub

  • edited 5:19AM

    Haha (no offence, you undoubtedly have a good cause, but the general image of scientists being on strike just hit my funny bone), you're on strike? Whatfor?

    Anyhow, you're welcome, good luck and keep me posted indeed!

  • edited March 2012

    Haha, I can see what you mean. But this wasn't, let's say, a science-strike, it was general strike (Spain). I'm not Spanish but I've been living here for some time now and I decided to join the cause. In fact, it was more like a gesture then anything else since the legislation in question has been already approved.

    Anyway, back to our experiment: I have tried the easy way and copied your code into fresh new experiment's script editor. The result after clicking apply was that all the items you defined appeared in the dust bin without any kind of structure. I tried to recreate the structure you described here. Apparently I'm doing something wrong:

    Variable 'number' is not set in item 'sketchpad_item'.
    You are trying to use a variable that does not exist. Make sure that you have spelled and capitalized the variable name correctly. You may wish to use the variable inspector (Control + I) to find the intended variable.

    Also, I edited the items so that they follow the definitions in the code you provided. I get just the welcome screen and this:

    An unexpected error occurred, which was not caught by OpenSesame. This should not happen! Message:
    unsupported operand type(s) for -: 'int' and 'str'

    Could you provide an .opensesame script?

  • edited March 2012

    Yeah, sure! Here it is: http://www.cogsci.nl/esdalmaijer/remember_sequence.opensesame. Or see here, right click on it and download it to your pc.

    Please let me know if you've got it, so I can take it off-line again (it's not really supposed to be there :p ).

  • edited 5:19AM

    Got it, and it does work. Thanks!

    Let's see if I can find the mistake I made, and more importantly (at the moment) - adapt it for my experiment. I let you know (since I smell some more issues... :) )

  • edited 5:19AM

    No problem! Good luck and keep me posted :)

  • edited 5:19AM

    Ok, so it works (using variable "number" to record the order and "stim" to recall it - if I got it right). Now, what if I want to use the previously recorded order again? The intention is:

    1. Presentation phase (where the random order is recorded)
    2. Immediate recall phase (where it is replayed - so far so good)
    3. Delayed recall & recognition - reproduce the once recorded order again - here is where I fail

    As for the third point, I simply tried to add the inline_script_3 item again before the delayed recall sketchpad (which is supposed to display the same set of images as in phase 2) to be able to recall the order, but I get the following mistake:

    Error: Inline script error
    In: inline_script_3 (prepare phase)
    Line: 2
    Python traceback:
    IndexError: list index out of range

    I have also tried to put the inline_script_2 item after the first immediate recall sketchpad (my thinking being - let's record the order again and again recall it), but it just repeatedly displays only one of the images.

    As I don't understand really how those 2 scripts work, it's difficult to modify them to get this work. Hint appreciated.

  • edited 5:19AM

    Ah, yes, I can see how that could be a problem. In the third inline, I used the OpenSesame default variable count_inline_script_3 to call a specific entry in our list (with the pictures that had high scores). This count goes up one every time inline_script_3 is run, which is perfect for the first time we use it (since it then calls stimage[0], stimage[1], stimage[2] etc. up to the final entry (stimage[4] in my example).

    The second use of that same inline_script_3, however, will cause OpenSesame to keep counting from where it left of, so now it will call stimage[5], which does not exist. Simple solution: add an inline_script_4, copy-paste everything from inline_script_3 and adjust the bit where it says 'count_inline_script_3' to 'count_inline_script_4'.

    Hope this helps!

    P.S. I'm writing this from an Android emulator on PC, lol!

  • edited March 2012

    Perfect! Solved.
    I intent to learn a bit more about Python when I have some time. But if you are not too busy, you could write a few words about how those scripts work - I imagine there is something to establish the new variables, then assigning a values etc but it would be great to have it described a little bit.

    Btw, in your note to the experiment, you are talking about calling the .bmp files during the presentation phase as file[number].bmp where [number] is the variable. However, I simply use the variable I had used originally [surname] which has values sur1 sur2...sur12 and it works without explicitly using the variable [number] in any (sketchpad) script. Then in "corresponding sequence" I use sur[stim].bmp in the sketchpad's script. The results are the same.

    Does this mean that I can delete the whole [surname] variable and use the [number] variable instead? E.g., to write sur[number].bmp in the presentation sketchpad script?

  • edited 5:19AM

    Yeah, that's exactly what it means! If you look at the script of a sketchpad that presents a picture, you'll see something like this:

    draw image 0.0 0.0 "[picname].bmp" scale=1.0 center=1 show_if="always"

    but you might as well change "[picname].bmp" to "picture[number].bmp". And since we're already using the number-variable, this would mean having to put less effort into making the experiment.

    And I'll gladly tell you a bit more about the scripting, although it's fairly self-explanatory and quite basic (but, then again, that's the perfect stuff to begin with).

    inline_script_1

    global stimage
    stimage = [] # define empty list

    line 1: usually, when you create a variable within an inline_script, it is only callable within that script. There's a couple of ways to extend the range. One of them is declaring it as a global variable (callable throughout the entire experiment). You simply do this by typing 'global variablename', as you can see above.

    line 2: by typing 'variablename = 1', you van assign an integer to your variable. Other possibilities include strings (stringvariable = "string" or stringvariable = 'string'), floats (floatvariable = 1.5), tuples (tuple = (1,2,3) ), lists (list = [1,2,3] ) and dictionaries (dictionary = {"key1":"value1","key2","value2"} ). In this case, we set up an empty list ('[]'), since we're going to use the function for adding values to a list in the next inline_script.

    inline_script_2

    global stimage
    stimage.append(self.get("number")) # add number of displayed item to list

    line 1: again, we declare 'stimage' global, so we van use it in our inline_script even though it was created in another.

    line 2: this is the function for adding values. It works by simply putting it behind a variable, like this: 'variablename.append()'. You van put the stuff you need added to your list in between of the brackets. In this case, this is the current value of the variable 'number'. For this, we can't simply call 'number', though, since it was set globally and we're trying to use it locally in this inline_script. For this, you can use the 'self.get("variablename")'-command. 'self.get()' first looks for a variable locally and then checks if it exists globally

    inline_script_3

    global stimage
    stim = stimage[self.get("count_inline_script_3")] # set local variable 'stim', to be used in sketchpad_corresponding
    self.experiment.set("stim",stim) # set it so that OpenSesame will be able to use it

    line 1: same as before.

    line 2: in the previous inline_script, we made a list containing the numbers in the order they were presented. In this inline_script, were going to use that list to call the same numbers again. By calling 'variablename[x]', we get the value of variablename's position x+1 (since Python starts counting at 0). So, in our case, stimage[0] = 3, if three would have been the first number presented. stimage[1] would provide the second, stimage[3] the third and so on. Of course, adding a variable would do the trick as wel: stimage[var] = 3 if var = 0. Because I was too lazy to add my own counter (and since OpenSesame can do it for me!), we use the 'self.get()'-command again, to access this counter: self.get("count_inline_script_3").

    line 3: the command seen here is quite similar to 'self.get()', only this one is used to set a variable instead of accessing one. It's used like this: 'self.experiment.set("variablename", value)'. In line 2, we created the local variable 'stim' (which contains the number on position 'count_inline_script_3' of the list 'stimage'). Now, we use 'self.experiment.set("stim", stim)' to set global variable 'stim' with value stim.

    In case you wonder: there is a command 'self.set()' too, but this is to assign values to local variables, whereas 'self.experiment.set()' is for global variables. 'self.get()', as stated before, looks at local variables first, but then at the global variables as well. That's why you van use 'self.get()', but probably want to steer clear of 'self.set()' and use 'self.experiment.set()' instead.

    Is this what you had in mind? Good luck with Python! Learning to use it a bit, is really worth the effort.

  • edited April 2012

    Hi Edwin!

    Thanks for the description! I finally got to it. It is not that self-explanatory for me so I'm glad you have been so thorough explaining it. ;-)

    If I understand correctly, OpenSesame adds 1 to the counter each time inline_script_3 is executed. Resulting value equals position within the list. Corresponding value is then retrieved from the stimage list by putting the counter as a value for stimage variable.

    To my question: Could you for instance introduce new variable that would equal to the script count, and then a conditional statement that would reset it to 1 each time it reaches the end of the list? Following code is most likely wrong but you might get the idea what I mean:

    mycounter = self.get("count_inline_script_3") # to establish the new variable and let it be equal to the script count
    If mycounter > 4 then mycounter = 1 # reset mycounter to 1 each time it exceeds 4; in other words, when it reaches 4, it actually goes back to the first position in the list
    stim = stimage[mycounter] #

    The purpose of this would be to avoid the necessity of renaming the script each time you want to use it (so during the first repetition, you would use the same inline_script_3 as in, say 10th repetition). Does this make sense?

  • edited 5:19AM

    Yeah, that makes sense! And your code is about right, but it's probably easier to set up your own counter from the start if you plan to do things like this (so the code will look a bit different).

    At the beginning of your experiment, put up an inline_script saying something like this:

    global mycounter # makes counter accessible in other inline scripts
    mycounter = 0 # set up counter

    Better still: add it to inline_script_1:

    global stimage
    global mycounter
    
    stimage = []
    mycounter = 0

    inline_script_2 is the same. Inline_script_3 will look like this:

    global stimage
    global mycounter
    
    if mycounter > 4:
        mycounter = 0 # reset to zero, since Python starts counting at 0, not at 1
    
    stim = stimage[mycounter] # set local variable 'stim', to be used in sketchpad_corresponding
    self.experiment.set("stim",stim) # set it so that OpenSesame will be able to use it
    
    mycounter += 1 # add one to the counter
    # this is actually the same as 'mycounter = mycounter + 1' (which you may use as well, but 'mycounter += 1' is simply shorter)

    Makes sense? Good luck!

    Edwin

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 http://45.77.173.118/ 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