[solved] Screen with buttons that can be pressed
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
Hi FLorian,
I'm sorry, but the solution is again rather easy (at least I think so).
So far I know,
widgetscan only be used informs. Therefore, you can't just add it to asketchpadand expect it to work. You have to use someform(like thebase_form) and paste it there. If you have a look on theformdocumentation things should get clear rather quickly.Eduard
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:
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
Hi,
@eduard: as you can see, I am still wrapping my head around the very basic concepts here. Thank you for your
) patience.
patients(hahahahah, sorry, I was very triedThank you both for the information. The documentation for the
formsgot me a lot further. I now used aform_baseitem, created the appropriate number of row and column, populated those withbutton widgetsand 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:
I'll have to place an
inline_scriptafter the form to do several checks based on which buttons were pressed. However, when checking the content ofresponse, I always get "yes", no matter which button was pressed:(This is also the case if I use a
feedbackitem 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!
Argh. I kept playing around and then realized that this works:
In
form_base:In
inline_script: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?
Hi,
maybe the
multiple_choice_formis 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
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...

Thanks!
Hi again,
just to document how I ended up doing this. My buttons are set up like this in a
base_formitem:Then I place an
inline_scriptitem after thebase_formwhich contains this code:Then I have the
button_idand can work with that. Not very elegant but functional.Seems to be a valid solution to me. You might want to add a
breakstatement in the end, to avoid pointless iterations in theloop, though.Eduard