Howdy, Stranger!

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

Supported by

[solved] Setting cycle variables from inline Python Script

edited August 2012 in OpenSesame

Hello,

how can achieve from within a python inline script the same thing as "setcycle 0 var1 val1" ?
( I have all my cases in a .csv file that I would like to load. So, I need to run the command above from within an inline script)

thanks
guido

Comments

  • edited 10:53PM

    Dear Guido,

    I think the simplest way to achieve your goal is, in fact, via the interface rather than an inline script. This is because you can easily paste the content of your .csv file into a loop item in the following way:

    • Create a loop item and add the names of your independent variables (e.g. 'var1') by clicking on the 'Add variable' button.
    • Set the number of cycles to the same number of cases in your .csv file. Now, the number of cells in the loop item will be equal to the number of cells in your .csv file.
    • Open your .csv file in a spreadsheet reader and copy all cases (but not the column headers, if you have them).
    • And then simply paste everything in the loop item.

    If you prefer to set your values via an inline script after all, please let me know and I will give you an example of this.

    Best wishes,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 10:53PM

    Update:

    On a general note I would like to add that communicating about variables between the GUI and Python inline code works very easily and as follows:

    • To get an in a loop defined variable in an inline_script, use:
        self.get("var")
        # Note that the to-be-retrieved variable name is a string.
        # The returned value can be a string, float, or int 
        # (the most appropriate is selected). 
    • To set an in an inline_script defined variable for future use in other items, such as a sketchpad or, importantly, the logger item, use:
        self.experiment.set("var", value)
        # Note that the to-be-set variable name is a string, and the value can be a 
        # string or numeric.

    See also the documentation on experiment functions.

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 10:53PM

    Thanks for the replies.
    I followed advice 1: prepared the experimental block in excell, built a column of setcycle num var1 val1 (using INDEX()), copied it into a .txt document, then copied into the script for the block, and adjusted the number of cycles. Once used to it, its is quite fast and flexible.

  • edited 10:53PM

    I would be grateful for a code example of how to do this inline.

  • edited 10:53PM

    I think I've found a way. Proof of concept code (inline script just before block_loop):

    top    = 192.5
    bottom = -192.5
    left   = 'left_button'
    right  = 'right_button'
    
    word_pos  = (bottom, bottom, bottom, bottom, top, top, top, top)
    pair_pos  = (top, top, top, top, bottom, bottom, bottom, bottom)
    probe     = (1,1,2,2,1,1,2,2)
    probe_pos = (bottom, top, bottom, top, bottom, top, bottom, top)
    correct   = (left, left, right, right, left, left, right, right)
    
    nwords = {
        0: (['Despair', 'Parting'],['Wound', 'Attic'],['Battle','Choose']),
        1: (['Suspicious', 'Discussion'],['Stinking', 'Receiver'])
        }
    string = ""
    for i in range(0,8):
        pair_num = 1
        string += "setcycle %d word_pos \"%s\"\n" % (i,word_pos[i])
        string += "setcycle %d word \"%s\"\n" % (i,nwords[pair_num][0][0])
        string += "setcycle %d probe \"%d\"\n" % (i,probe[i])
        string += "setcycle %d pair_pos \"%s\"\n" % (i,pair_pos[i])
        string += "setcycle %d pair \"%s\"\n" % (i,nwords[pair_num][0][1])
        string += "setcycle %d probe_pos \"%s\"\n" % (i,probe_pos[i])
        string += "setcycle %d correct \"%s\"\n" % (i,correct[i])
        string += "run trial_sequence\n"
    
    bl = exp.items["block_loop"]
    bl.from_string(string)
    bl.cycles = 8
    
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