Variables, operators and formulas: a score that adds itself up
Keep score with Adjust variable: add, subtract, multiply, divide, remainder, a random number, or a formula such as Score * 2 + Bonus. Show the value on the slide with %Score%, as in Storyline.
Last updated 5 min read
How do I add points, double a score or pick a random number without JavaScript?
Step by step
Make three number variables
Variables → Add Variable:
Score(0),Bonus(5) andTotal(0), all number.Add points on a click
On a button, add a trigger Then → Adjust variable →
Score→ Add (+) → 10.Work out a total with a formula
On a second button, Adjust variable →
Total→ Expression →Score * 2 + Bonus.Show the values
In a text box, type
Score: %Score% Total: %Total%.Try it
Preview. Click the first button twice, then the second: the text shows Score: 20 and Total: 45.
What you'll build
A slide with an Earn 10 points button, a Work out my total button, and a line of text that shows the numbers as they change. It is the core of every gamified quiz, built with no JavaScript.
Step 1: the variables
Click Variables on the toolbar, then Add Variable three times:
Score, number, starting at 0.Bonus, number, starting at 5.Total, number, starting at 0.
Names start with a letter and use letters, numbers and underscores. They are case-sensitive: score and Score are two different variables.
Step 2: add points
Add a Button and set its Label to "Earn 10 points". Add a trigger and open it.
- Then: type "adjust" and pick Adjust variable.
- Pick
Score. - Operation: Add (+). Amount: 10.
The other operations are the ones Storyline has: Subtract (−), Multiply (×), Divide (÷), Remainder (%) and Assign (=). Switch Value to Variable to add another variable instead of a number, Storyline's "Variable" option.
Step 3: a formula
Add a second button, "Work out my total", with an Adjust variable action on Total. Set Operation to Expression and type:
Score * 2 + Bonus
An expression can use numbers, variable names, + - * / % and brackets. That is all, so it can never run code, and it works the same in every LMS. Storyline needs JavaScript for this; here it is one action.
Random whole number is there too: pick it, set From and To, and the variable gets a number in that range each time the trigger runs.
Step 4: show the values in text
Add a Text box and type, exactly as you would in Storyline:
Score: %Score% Total: %Total%
In the editor you see the names. Learners see the numbers, and they update the moment a trigger changes them.
The player's own results work the same way: %Results.ScorePoints%, %Results.ScorePercent% and %_player.MaxPoints%.
Try it
Click Preview. Click Earn 10 points twice: the text shows Score: 20. Click Work out my total: Total shows 45 (20 × 2 + 5).
Tip: React to a change with When variable changes. For example: when Score changes, only if Score is at least 50, show a "Level up" layer.
Part of the documentation: Build.
Found something here that does not match what the product does? That is a bug in the guide — see all guides or tell us from the Help Center.