Howdy, Stranger!

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

Supported by

Counterbalancing images position in OpenSesame

Hello everyone,

I am designing a picture selection task in OpenSesame where participants hear a spoken sentence while two images are displayed on the screen (i.e., a target and a distractor image). Their task is to listen to each sentence and then, select the picture that best represents what they just heard.

I am currently trying to counterbalance the position of the two images in such a way that the target image does not always appear on the left side of the screen, but I cannot find the way to do it.

Additionally, I want to associate a keyboard responde (f;j) to each image (target, distractor) because participants will be asked to press the f or j key depending on whether they want to select the image on the left or right side, respectively. I am having trouble with this too, particularly if a randomise the position of the target and distractor images.

If someone has done this before and know how I can proceed, I would truly appreciate the help.

Thank you very much in advance,



  • Hi @egarcia,

    There are several options. If you want complete counterbalancing (as opposed to randomization), the simplest option is to design the content of the loop accordingly (that is, you make sure that you enter trials details in the loop that correspond to a counterbalanced design). The definition of the correct response is then simple, you simply include a correct_response column and indicate for each trial which is the correct response (f or j).

    if you want to randomly position two images is to create two image holders on your slide, set the names of the files to be displayed in distinct columns in your loop, and to use the shuffle_horiz function to randomly shuffle these columns (see; see documentation; . The definition of the correct response would be a little more complex and require some coding (though if you do not need to calculate scores in the task, you can also envisage scoring the response offline, in the data output, for example using formulas in Excel). Alternatively to using shuffle_horiz, you could also determine the location of the image and define the correct response entirely through code.

    Hope this helps,


    Buy Me A Coffee

  • Hi Fabrice,

    Thanks a million for your help, it is indeed useful. I checked the links and the the shuffle_horiz function seems great to randomise the position of the images. However, regarding definition of the correct response, do you know if there is a webpage or experiment example where I can see a code similar to the one that I need to implement in my experiment?

    Thank you very much again. It means a lot.



  • Hi @egarcia,

    I'm glad that the shuffle_horiz helped. For randomizing the position of the pictures, it is the simplest method.

    Regarding the scoring of the responses, as you may have guessed, the difficulty is that you can't simply define one of the keys as the correct response since you don't know where each picture will appear in each trial. Hence, the goal is to write some code that will look into the response provided by the participant, identify the picture that was presented on the side corresponding to the key pressed, compare that to the correct response, and set the score accordingly.

    In Open Sesame, you can write code in Python or in Javascript, using inline_script or inline_javascript objects respectively. Here I'll use Python, but the result could be obtained using Javascript language instead.

    For this example, I set up a very basic task in which a word appears at the center of screen, flanked by pictures (of forest or city) on the left and on the right, and participants must press the F or J keys to indicate where the object corresponding to the word is more likely to be found (e.g., "bird" is more likely to be found in the forest and in the city).

    Here's the general structure of the task:

    You can see that I'm using shuffle_horiz in the script of the loop to randomly shuffle the content of the image1 and image2 columns. Note that I define the correct_response as the image that should be selected by the participant and not as the key they press (more on this later).

    The stimuli slide contains the word and the image holders:

    Because the shuffle_horiz command shuffles the content of the columns and not the columns themselves, image1 will always correspond to the image shown on the left on the slide above (and image2 will always appear on the right).

    Hence, what we need to do right after a response has been detected, is to identify which key was pressed, and then check whether the image shown on the side corresponding to that response is the mage defined as the correct response. So, if the response if "f" or "F", we know that the participant selected the left picture, otherwise he/she selected the picture on the right. if they pressed F, we'd check whether the picture shown as image1 is the same or not as that we defined as correct_response. If it is, then the response would be correct and we'd manually set the score to 1, otherwise to zero. Similar logic if the key pressed is not "f" or "F" (in which case, it is "j" or "J"), but now comparing image2 to correct_response. Here's the code doing this in Python (highlighted in the yellow section):

    I introduced the code highlighted in the green section just to keep track of what's going on (it outputs data in the console so that you can check that the score is calculated correctly on each trial).

    Python is not difficult to learn for simple things like these (I don't personally know Python well at all, but searching the web as little, you quickly learn how to di basic things like if...then loops.

    Then you just need to know how to access variables from OS in Python, which is simply done by prefixing "var." to the name of the variable. You can find information about key response variable here: (alternatively, if you look at the data log, the first row will contain a lot of variable names showing what is what).

    If you're new to Open Sesame, I definitely encourage you to spend some time going through the documentation/tutorials and dedicate some time to learning basic Python (or Javascript). Python is more powerful but would allow your Open Sesame task to run in a browser (to do so, Javascript must be used).

    You can download my example here:

    Does this help?.


    Buy Me A Coffee

  • Hi @Fab,

    Thank you very much for such a detailed response, I truly appreciate your help!! Over the past days I have been going through the resources you recommended (tutorials, documentation) and working on the coding for the experiment and it seems to work now.

    I would like to share here a code that may be implemented in case it is useful for someone.

    In the experiment, participants see two images simultaneously on the screen (i.e., target_image and distractor_image), whose position is randomised. To do so, I added two variables (or columns) to the block_loop table (i.e., target_location and distractor_location) and I specified the positions of each image (left for the target image, and right for the distractor image). This was afterwards randomised using the shuffle_horiz function as follows:

    shuffle_horiz target_location distractor_location

    Finally, given the fact that the position of the images was defined by values like left and right, their exact coordinates were typed in the sketchpad display_images script:

    The option you suggested, Fab, works perfectly fine. This is just another idea I came up with and I wanted to share it in case it may be of help for someone.

    Once more, thanks a million!



  • Hi @egarcia,

    Glad you worked it out and that your task is working. Thanks for sharing your solution!



    Buy Me A Coffee

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