Formulas
Name a calculation once as a formula and reuse it in any value across your design.
Formulas
A formula is a named calculation — an upgrade cost, a damage multiplier — that you define once and use wherever a value is expected. Change the formula, and every value that uses it changes with it. You manage formulas from the Formulas tab of the Element Explorer on the Design tab.
Creating a Formula
In a workspace, click New Formula, name it in the Inspector — e.g. "Upgrade cost", with the slug upgrade_cost — write its Expression and click Save. A new formula's expression is 0. The fields every element shares are covered in Navigating Leap Studio.
The Expression is the calculation. Click # to build it in the expression builder; once built, it's shown as a chip and written out underneath. See Values and Expressions. As the Inspector puts it: "Worked out wherever it is used — game clients never see a formula, only the values it produces."
Using a Formula
In any value field that offers it, click ƒ and pick the formula — in an effect's amount, the value a condition compares against, an outcome's weight, or another formula's expression. In the builder, add a ƒ Formula block, or type @upgrade_cost (or @formula/upgrade_cost).
The value below uses the Upgrade cost formula of the example game (base_damage × 5 + 10):
A formula can't be used on the left side of a condition — compare an element against the formula instead.
Where a Formula Can Be Used
A formula that isn't in any group can be used everywhere. A formula inside a group can be used by elements in that group or in groups inside it. Where no formula can be used, the builder's ƒ Formula button explains: "a formula must be ungrouped, or in this element’s group or a group above it".
Used By
The Used by section of the Inspector lists every value that uses the formula. When nothing does, it reads "Nothing uses this formula yet. Pick it with the ƒ Formula block in any value expression."
If you delete a formula, Leap tells you how many values use it before you confirm: they're left pointing at nothing, and the next merge fails until you replace them.
Formulas Can't Form a Loop
A formula can use other formulas, but not in a loop. If saving would make formulas use each other in a circle, Leap refuses and shows the loop, e.g. "This makes formulas use each other in a loop: “A” → “B” → “A”. A formula must not use itself, directly or through other formulas." Merges are checked the same way, in case two workspaces each add half of a loop.
Next Steps
Continue to Operations and Effects.