Variables and Interactive Controls
Use variables to connect components and create lessons that respond to learner input.
A variable is a named value that persists across a lesson. Components can write to variables (a slider sets a value, a learner types their name) and other components can read from them (a text block displays the value, a visibility condition checks it).
Creating a variable
Open the Variables tab in the lesson sidebar. Click Add Variable and give it a name. Variable names should be lowercase with no spaces — score, userName, selectedPath are all valid names.
You can set a default value if the variable should start with something specific.
Binding controls to variables
Input components — like text inputs, number inputs, and sliders — have an Output Variable setting. Set it to a variable name, and whenever the learner changes the input, the variable updates automatically.
For example:
- A Slider with an output variable of
ratingupdatesratingas the learner drags - A Text Input with an output variable of
userNamecaptures whatever the learner types
Some question components also track answers in variables. A Multiple Choice question can store the selected choice ID in a variable for use later in the lesson.
Conditional visibility
Every component has a Visibility Condition setting. You can write a condition using variable values, and the component only appears when the condition is true.
Common patterns:
- Show a “Correct!” message only when
score >= 8 - Show a hint block only after the learner has made an attempt:
attempts > 0 - Show different feedback based on which path the learner chose:
selectedPath == "B"
Conditions update in real time as variables change. If a learner earns enough points mid-step, the congratulations message appears immediately.
Linking components together
Variables are how components communicate. A few examples:
Fraction bar + slider — A slider sets a numerator variable. A custom fraction bar widget reads numerator and updates its display in real time. The learner drags the slider and watches the visual respond.
Score tracker — Multiple choice questions add to a score variable. A results screen displays Your score: {{score}} and conditionally shows different feedback based on the score range.
Personalized intro — A text input on the first step captures the learner’s name into userName. Every subsequent step can address them by name.
Exact decimals (money and measurements)
Computers store decimals like 0.1 approximately, so 0.1 + 0.2 comes out as 0.30000000000000004. A condition like total == 0.3 can then fail, and a stepper counting by 0.1 may never quite reach its maximum.
When a lesson needs exact decimals, store whole numbers in a smaller unit and convert only for display:
- Name the variable after its unit. Use
price_centsinstead ofprice, ormass_mginstead ofmass_g. $12.50 is stored as1250. - Do all the maths and checks in that unit.
{{price_cents}} * {{qty}} >= 5000uses whole numbers, so it’s always exact. - Set up controls in the stored unit.
- On a Slider, Stepper, Dial, Progress Bar or Numeric Display, enter whole-number min, max and step (for example 0, 10000 and 5).
- Set Display Scale to
100and Number Format to$0.00. - The learner sees $0.05 steps, and the variable holds whole cents.
- Show values with a scale.
- Give a numeric expression the format
$#,##0.00and scale100. - In a string expression, use
{{format price_cents "$#,##0.00" 100}}.
- Give a numeric expression the format
- Collect typed values with a scale. Set a number input’s scale to
100. The learner types dollars, and the variable stores cents.
For measurements, choose the scale from how many decimals you need: 10 for one decimal place, 100 for two, 1000 for three.
Common patterns
Show feedback after an attempt — Add a question and a feedback text block. Set the feedback block’s visibility condition to attempted == true. The block appears only after the learner submits.
Display results based on score — Create multiple result blocks, each with a different visibility condition (score < 5, score >= 5 && score < 8, score >= 8). Only the appropriate block appears on the results step.