Howdy, Stranger!

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

Supported by

[solved] Screen with buttons that can be pressed

floflo
edited December 2015 in OpenSesame

Hi ,

I am using OpenSesame 2.9.6 on Mac OS Yosemite.

For my experiment, I need a screen that shows a bunch of "buttons" that represent different response options. I've been thinking about how to best implement this and have stumbled upon the image_button functions/widget. They seem useful and like exactly what I need.

I can't seem to get it to work, though. When I paste the OpenSesame code to the script window of a sketchpad item, it is automatically removed:

widget 0 0 1 1 image_button path='test.png' var='response'

This is odd.

My more general question is: is there a tutorial/example that shows how to implement image_buttons and how to collect responses from them?

I guess I could do this by drawing rects and recording mouse clicks and then determining whether a click was inside one of the rects. That'd be very annoying (and error-prone), though. So using some kind of ready-made button would be a much nicer solution.

Thanks for any help!

  • Florian

Comments

  • edited 5:47PM

    Hi FLorian,

    I'm sorry, but the solution is again rather easy (at least I think so).

    So far I know, widgets can only be used in forms. Therefore, you can't just add it to a sketchpad and expect it to work. You have to use some form (like the base_form) and paste it there. If you have a look on the form documentation things should get clear rather quickly.

    Eduard

    Buy Me A Coffee

  • edited December 2015

    Hi Florian,

    Edit: i'm rather slow, so Eduard already answered most of it :)

    The widget functions only work with form items, not on the sketchpad items. It took me a while to figure that out as well.

    For your second question: i think that the image_button functions work similar to the touch response items in which a raster is created by setting the amount of columns and rows. So you could set the amount of squares directly in the form item by adjusting the rows and columns there:

    set rows "2;2"
    set margins "50;50;50;50"
    set cols "2;2"
    

    Then you can place your image button widget at the desired rectangle and collect the variable response you defined in the widget. The variable will be set to "yes" once the participant clicks anywhere in that area of the raster, so make sure the image 'fits' the rectangle.

    Laurent

  • floflo
    edited December 2015

    Hi,

    @eduard: as you can see, I am still wrapping my head around the very basic concepts here. Thank you for your patients (hahahahah, sorry, I was very tried :D) patience.

    Thank you both for the information. The documentation for the forms got me a lot further. I now used a form_base item, created the appropriate number of row and column, populated those with button widgets and changed the text accordingly.

    Now on to the next problem: How do I figure out which button was pressed? All my buttons are created using this format:

    widget 0 0 1 1 button var="response" text="button 1"
    widget 0 1 1 1 button var="response" text="button 2"
    

    I'll have to place an inline_script after the form to do several checks based on which buttons were pressed. However, when checking the content of response, I always get "yes", no matter which button was pressed:

    print exp.get('response')
    

    (This is also the case if I use a feedback item and display the text "response: [response]" - it is always "yes".

    I want to record record the time stamp of the click and have to know which button was clicked.

    Thank you for your time, guys!

    • Florian
  • floflo
    edited 5:47PM

    Argh. I kept playing around and then realized that this works:

    In form_base:

    widget 0 0 1 1 button var="response" text="button 1"
    widget 0 1 1 1 button var="response2" text="button 2"
    

    In inline_script:

    print exp.get('response') + " and " + exp.get('response2')
    

    This prints "yes and no" when I press "button 1" and vice versa.

    This wouldn't be so bad if I only had two buttons. But I have 30+. I don't want to chain together 30+ if-statements to figure out which button was pressed. :( Is there a smarter way of doing this?

    • Florian
  • edited 5:47PM

    Hi,

    maybe the multiple_choice_form is something for you? I couldn't find a documentation about this plug-in, but if you open opensesame you can add the item to your experiment and play around with it (it's the small green box with "a)" and "b)" written in it.

    Eduard

    Buy Me A Coffee

  • floflo
    edited 5:47PM

    Hi Eduard,

    this was my first idea as well and I played around with it. But there are too many options and it's not quite what I need.

    If there's a better solution, I'd love to hear about it. Until then, I am going to just chain a trillion if-statements to figure out which of the 30+ button was pressed... :( :D

    Thanks!

    • Florian
  • floflo
    edited 5:47PM

    Hi again,

    just to document how I ended up doing this. My buttons are set up like this in a base_form item:

    widget 0 0 1 1 button var="resp_1" text="button 1"
    widget 0 1 1 1 button var="resp_2" text="button 2"
    ...
    widget 0 2 1 1 button var="resp_31" text="button 31"
    

    Then I place an inline_script item after the base_form which contains this code:

    button_id = 0
    for i in range(1, 32): #  highest resp_[num] + 1
        if exp.get('resp_' + str(i)) == 'yes':
            button_id = i
    

    Then I have the button_id and can work with that. Not very elegant but functional.

    • Florian
  • edited 5:47PM

    Seems to be a valid solution to me. You might want to add a break statement in the end, to avoid pointless iterations in the loop, though.

    Eduard

    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 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