Howdy, Stranger!

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

Supported by

Button coding wrong value of variable

edited March 2017 in OpenSesame

Hi everyone,

I've searched for a long time and I can't seem to find why my code isn't working properly :(. I'd be very glad if you could help me solving my code, which I'm sure is not that complicated, I think I just miss some bit of information.

My goal is to create a form which contains a label and two buttons, each one coding a different value of the same variable (locus). The problem is that my scale items are always coded the same value, not depending on which button i've clicked.
So far, i've embedded an inline_script into a sequence into a loop. Here is a screenshot of my plan :

To make it easier to understand, here is a screenshot of my loop :

Each line contains 2 texts, respective to each button. Here is what the subject sees :

I've writen this text in the inline_script "run" category :

from libopensesame import widgets
form=widgets.form(exp, margins=(250,50,250,50), cols=[1], rows=[1,1,1])
label=widgets.label(form, text="Veuillez choisir l'affirmation avec laquelle vous êtes le plus d'accord.")
button_1=widgets.button(form, text=var.scale_question, var='bouton')
button_2=widgets.button(form, text=var.scale_question_2, var='bouton')
button_1.set_var('interne', var='locus')
button_2.set_var('externe', var='locus')
form.set_widget(label, (0,0))
form.set_widget(button_1, (0,1))
form.set_widget(button_2, (0,2))
form._exec()

if var.recode=='yes':
    if var.locus=='interne':
        var.locus='externe'
    elif var.locus=='externe':
        var.locus='interne'

var.reponses_items=var.locus

The problem is that the lines with the 'recode' value of 'no' always code 'locus' to 'externe', whereas the lines with the 'recode' value of 'yes' always code 'locus' to 'interne'.
How do I manage to code the value of 'locus' depending on the button the subject has clicked ?

For information, the 'recode' variable switches the values of locus _because the sentences in a '_yes' item are switched to prevent an order effect.
The 'reponses_items' variable is just a global variable I use to have a cleaner finale sheet.

Thank you for reading :smile:

Comments

  • Hi Olivier,

    Thank you for your polite and detailed question (this makes me more willing to try to answer it :) ).

    If you use the inline below I think it should work. Note I changed the button_1 and button_2 lines and the if statements and removed the set_var lines as I don't really understand what they should do in any experiment B)

    from libopensesame import widgets
    form=widgets.form(exp, margins=(250,50,250,50), cols=[1], rows=[1,1,1])
    label=widgets.label(form, text="Veuillez choisir l'affirmation avec laquelle vous êtes le plus d'accord.")
    button_1=widgets.button(form, text=var.scale_question, var='bouton_1') #<<<<<
    button_2=widgets.button(form, text=var.scale_question_2, var='bouton_2') #<<<<<
    form.set_widget(label, (0,0))
    form.set_widget(button_1, (0,1))
    form.set_widget(button_2, (0,2))
    form._exec()
    
    if var.recode=='yes':
            if var.bouton_1=='yes': #<<<<<
                    var.locus='externe'
            elif var.bouton_2=='yes': #<<<<<
                    var.locus='interne'
    
    var.reponses_items=var.locus
    

    Best,
    Jarik

    PS I don't understand why one would use the button.set_var() function. Can anyone clarify? Possible the set_var documentation needs some more details or an example?

    http://osdoc.cogsci.nl/3.1/manual/forms/widgets/button/#function-button46set95var40val-varnone41

  • Hi Jarik, thank your for your help !
    It works like a charm :D
    Although I don't really understand how the variable 'locus' is assigned a value since we didn't create it in the first place. It must be a Python thing ^^.
    Here is the resulting code :

    By the way, I'd be interested too in the 'button.set_var( )' function usefulness.

    Thanks again, have a good day !

  • Although I don't really understand how the variable 'locus' is assigned a value since we didn't create it in the first place.

    Yes you did! Once you've done var.locus = 'some value', the variable 'locus' exists. Or is that not what you mean?

    By the way, I'd be interested too in the 'button.set_var( )' function usefulness.

    This is essentially an internal function, which is used by the button widget itself. It's documented for completeness, but I cannot really think of a situation in which it would be useful for regular users.

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