Howdy, Stranger!

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

Supported by

Defining variables in inline python script

edited December 2022 in OpenSesame

Hi everyone, I am just starting with OpenSesame, and I have an issue which is pretty straightforward but to which I could not find a solution in the forum.

I am trying to define two lists in an inline script, and appending numbers and symbols from the "number" and "symbol" variables defined through a sequential loop. My aim is to then randomize the symbol-number pairings across different experiment runs, maintaining consistency within the individual run.

I am using the following code, which is the format I would use in psychopy:

# This runs in the 'Prepare' block
numbers_list = []
symbols_list = []

# This runs in the 'Run' block

However, I get the following error: "The variable 'numbers_list' does not exist."

I have tried defining them with the syntax "var.numbers_list = []" but I get the same error.

Any advice is greatly appreciated.


  • edited December 2022

    So, after some trial and error, I was able to define the variables using this syntax:

    import numpy as np
    exp.set('numbers_list', list(np.arange(1,10,1)))
    exp.set('symbols_list', [])

    However, after running a loop containing the following inline code, the symbol list still shows up as empty.


  • Hi,

    if you fill your loop in the run phase, you need to use a feedback item to present it, otherwise it will only show its state that it had before the run phase started. See this for more details:

    Hope this helps,


    Buy Me A Coffee

  • Thank you for your reply, Eduard. I will try to explain more clearly what I am attempting to do, as being pretty new to OpenSesame, I am not even sure that it is the right process.

    Basically, I am trying to recreate a digital version of the Symbol-Digits Modalities Test, in which participants need to press the number (between 1-9) corresponding to a symbol displayed randomly at the center of the screen, based on symbol-number pairings displayed in a legend at the top of the screen. Additionally, I need to randomize the symbol-number pairings across different test trials, to allow for repeated testing.

    I was able to do this in psychopy by loading my symbols at the beginning of the experiment with a random loop, which appended each symbol to a list variable. I then zipped my symbol and numbers lists into a dictionary, which I used to display the legend and to determine correct responses for each stimulus presentation.

    My issue atm is that I seem to be able to create the lists through a "loader" loop

    but then I am not able to access individual numbers or symbols in a subsequent "experimental" loop via normal python indexing (e.g. using var.symbols__list[0]in a sketchpad script or [numbers_list[0]] in a sketchpad textline element).

    It is very much likely that the whole process is wrong, or that I am making some rookie mistake, but I was unable to find specific info for my use case.

  • Hi @michedini ,

    Thanks for your interest in OpenSesame and welcome to the forum. I would advise you to have a look at our tutorials to get a grasp on how OpenSesame works, and especially how you can build a typical experimental hierarchy with block and trial levels.

    To achieve your goal, I think you should:

    • Define your dictionary at the very beginning of your experiment (i.e. at the top level of the hierarchy), for example with an inline_script item with the following Python code in the Prepare tab:
    import random
    # Define two lists:
    l_digits= [1,2,3,4,5,6,7,8,9]
    l_symbols = ["A","B","C","D","E","F","G","H","I"]
    # Shuffle:
    # Convert to dictionary with numbers as keys and symbols as values:
    dictionary = {l_digits[i]: l_symbols[i] for i in range(len(l_digits))}

    • Next, at the trial level, determine the values of the variables that belong to the current trial. Use the .var notation to store the variables for future use in the GUI. The Python script would look something like this (make sure to put it in the Prepare tab again):
    # NOTE that the trial_number variable is defined in the blockloop:
    var.trial_symbol = dictionary[var.trial_digit]
    # NOTE also that the correct response is identical to the trial digit
    var.correct_response = var.trial_digit
    • Your overview area should now look something like this:

    • Finally, you can show the current trial values in a sketchpad item.

    I attached a working example (including instructions and feedback, in case you were interested in that, too).

    Just let us know if you have any further questions.



    Did you like my answer? Feel free to 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