You are viewing unmaintained documentation for an older version of OpenSesame. Click here to view the current documentation. Your version of OpenSesame: Language:

OpenSesame 3.0.0 will bring amazing new features! Curious? Take it for a test spin, and help us iron out the kinks.

Form variables

If you experience performance issues when using forms, see this post.

About form variables

When you present a form with multiple checkboxes, you generally want to know which checkbox the user has checked. Similarly, when you present a form with two buttons, you want to know which button the user has clicked. This information is available through variables that are automatically set when the user interacts with a form. You can specify yourself which response variables should be used. How this is done depends on how you have created your form:

In ready-made form_* plug-ins

When you use one of the ready-made form plug-ins, such as form_text_input, you can specify the name of the response variable directly in the plug-in controls.

In custom forms

You can use the var keyword to indicate which variable should be used. For example, the following OpenSesame script, which you can enter into a form_base plug-in, indicates that the response from a text_input widget should be stored in a variable called my_response_var:

widget 0 0 1 1 text_input var="my_response_var"

The equivalent Python code is:

my_widget = widgets.text_input(form, var='my_response_var')

Widget-specific notes

Each widget uses its response variable in a slightly different way.

button

The button widget sets the response variable to ‘yes’ if it has been clicked and to ‘no’ if it has not.

checkbox

The checkbox widget sets the response variable to a semicolon-separated list of the text on all checkboxes in the same group that have been checked, or ‘no’ if no checkbox has been checked. This sounds a bit complicated, so let’s see a few examples.

widget 0 0 1 1 checkbox group="1" text="A" var="my_response_var"
widget 1 0 1 1 checkbox group="1" text="B" var="my_response_var"
widget 1 1 1 1 button text="Next"

Here there are two checkboxes with the text ‘A’ and ‘B’. Both part of the same group, called ‘1’. Both have the same response variable, called my_response_var. If ‘A’ is checked, my_response_var will be ‘A’. If ‘B’ is checked, my_response_var will be ‘B’. If neither is checked, my_response_var will be ‘no’. Note that only one checkbox in the same group can be checked, so my_response_var will never be ‘A;B’ in this example.

widget 0 0 1 1 checkbox text="A" var="my_response_var"
widget 1 0 1 1 checkbox text="B" var="my_response_var"
widget 1 1 1 1 button text="Next"

Now let’s consider the same script, with the sole difference that the two checkboxes are not part of a group. In this case, the situation is much like described above, with the exception that both checkboxes can be checked at the same time, in which case my_response_var will be set to ‘A;B’.

image

Variables are not applicable to the image widget.

image {#image}_button

The image_button widget sets the response variable to ‘yes’ if it has been clicked and to ‘no’ if it has not.

label

Variables are not applicable to the label widget.

rating_scale

The rating_scale widget sets the response variable to the number of the option that has been clicked, where ‘0’ is the first option (zero-based indexing). If no option has been selected, the response variable is set to ‘None’.

text_input

The text_input widget sets the response variable to the entered text.