(2) Instruction Block¶
Here, we learn how to create an instruction block. We creat a block greeting the participants and give instruction for the tasks. We get familiar with the different options to customize text stimuli.
Installing sweetbean¶
Do you remember how to install the package?
# Enter your code here:
Solution¶
!pip install sweetbean
Creating text stimuli¶
Do you remember how to import the functionality to create text stimuli?
# Enter your code here:
Solution¶
from sweetbean.stimulus import Text
Adding features to text stimuli¶
This time, we want to add more functionality to our stimulus. Remember:
introduction_stimulus = Text(text='Welcome to our awesome experiment.')
Duration¶
This stimulus has only one single parameter. The text parameter that defines what text is shown. But as we defined it, this stimulus would be shown indefinitely until the user closes the browser. To change this, we can add a duration parameter. The duration parameter is accepted by most stimuli types in SweetBean. It defines how long a stimulus is shown in ms.
introduction_stimulus_timed = Text(duration=4000, text='Welcome to our awesome experiment.<br>The introduction will start in 4s.')
The introduction will start in 4s.')
By adding the duration parameter, this stimulus will now be shown 4000ms.
Optional: What is that <br> - tag in the text parameter?
The text parameter in a text stimulus is a HTML-text and we can use HTML-code to create it. The <br> tag marks a line break.Responses¶
The timing of a stimulus is useful, but what if the for example, the introduction text is very long, and we want to give the participant the freedom to proceed whenever ready?
For this purpose we can define a list of choices. These are keys on the keyboard, that will be recorded when the user presses them. They also end the current stimulus.
introduction_stimulus_respond = Text(text="This is a very detailed explanation of our experiment.<br>Press SPACE to continue.", choices=[' '])
Press SPACE to continue.", choices=[' '])
The choices parameter expects a list of characters. Here, we chose the SPACE character (whitespace). We can also add more or different characters. For example, can you write a stimulus that asks for the participants handedness and accepts the letters r
, l
or o
as choices?
# Replace None in the following line:
introduction_survey_handedness = None
Solution¶
introduction_survey_handedness = Text(text="What is your handedness?<br>Press R for right, L for left, or O for other.", choices=['r', 'l', 'o'])
Press R for right, L for left, or O for other.", choices=['r', 'l', 'o'])
Survey Tool¶
The described way to ask for demographic data is just a demonstration. SweetBean has extra functionality to conduct surveys and to design questionnaires.
Creating a block¶
Do you remember how to create a block with the stimuli?
# Enter your code:
Solution¶
# import the functionality from sweetbean to create a block
from sweetbean import Block
# create a list of stimuli for the block
introduction_list = [introduction_stimulus_timed, introduction_stimulus_respond, introduction_survey_handedness]
# create the block
introduction_block = Block(introduction_list)
Creating the experiment¶
Do you remember how to create the experiment?
# Enter your code:
Solution¶
# import the functionality from sweetbean to create experiments
from sweetbean import Experiment
# create a list of blocks
block_list = [introduction_block]
# create the experiment
experiment = Experiment(block_list)
Exporting the experiment in html format¶
Do you remember how to export the experiment to html?
# Enter your code:
Solution¶
# create the html file.
experiment.to_html('index.html')