This SightLab example demonstrates how to display a series of dialog prompts to collect participant demographic and consent information using Vizard’s vizinput module, and log each response to the experiment summary.
Overview
Before trials begin, participants are prompted to enter age, gender, ethnicity, employment status (and job title if employed), and name. A final consent message appears before the main simulation starts.
Code Example
importsightlab_utils.sightlabasslfromsightlab_utils.settingsimport*# Initialize SightLab (default GUI mode)sightlab=sl.SightLab()defsightLabExperiment():# Wait for experiment start triggeryieldviztask.waitEvent(EXPERIMENT_START)# Allow resetting view with 'R' keyviz.callback(viz.getEventID('ResetPosition'),sightlab.resetViewPoint)fortrialinrange(sightlab.getTrialCount()):# Wait for trial start eventyieldviztask.waitEvent(TRIAL_START)importvizinput# Store responses in a dictresponses={}# --- Demographic Prompts ---responses['Age']=vizinput.input("What is your age?")responses['Gender']=vizinput.choose("What is your gender?",["Male","Female","Other","Prefer not to answer"])responses['Ethnicity']=vizinput.choose("What is your ethnicity?",["White/Caucasian (non-Hispanic)","African American","Hispanic/Latino","Asian/Pacific Islander","Middle Eastern/West Asian","Other"])# Yes/No returns 1 or 0responses['Employed']=vizinput.ask("Are you currently employed?")# If employed, ask for job titleifresponses['Employed']:responses['Job Title']=vizinput.input("What is your job title?")# Log each responseforkey,valueinresponses.items():sightlab.setExperimentSummaryData(key,value)# --- Name & Consent ---vizinput.message("Please enter your name in the space provided.")responses['Name']=vizinput.input("Enter your name:")sightlab.setExperimentSummaryData('Name',responses['Name'])vizinput.message("By clicking continue, you consent to participate. The simulation will begin after you close this dialog.")# put any other code to run to run in your trial#wait for the specified end trial condition (either set in the GUI or code. Spacebar in this case)yieldviztask.waitEvent(TRIAL_END)# Schedule SightLabviztask.schedule(sightlab.runExperiment)viztask.schedule(sightLabExperiment)
How It Works
Initialization: A SightLab instance is created in default (GUI) mode.
Start Events: The script waits for EXPERIMENT_START and TRIAL_START events before showing any dialogs.
Demographic Collection:
vizinput.input(prompt) opens a text-entry dialog.
vizinput.choose(prompt, options) opens a multiple-choice dialog.
vizinput.ask(prompt) returns a boolean-like value (1 = Yes, 0 = No).
Logging: Each answer is stored via sightlab.setExperimentSummaryData(key, value) for later export.
Consent Prompt: A final message confirms participant consent.
Flow Control: yield viztask.waitEvent(TRIAL_END) signals the end of the dialog trial.
Customization Options
Additional Questions: Insert more vizinput calls for questionnaires or experience ratings.
Validation: Add Python checks on input (e.g., numeric ranges for age) before logging.
Sequential Triggers: Use textContinueEvent in startTrial to tie dialogs to button presses.
GUI Integration: Combine with SightLab’s GUI workflow to launch dialogs automatically.
Running the Example
Place this script in your Sightlab project folder.
Adjust trial count or environment settings via your SightLab GUI or settings.py.
Launch in Vizard/SightLab; dialogs will appear before each trial sequence.