Loading Leap…

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

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

Click ƒ ("Use an existing formula") and pick the formula — in an effect's amount, on either side of a condition, or in an outcome's weight. In the expression builder, including another formula's Expression, 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):

On the left side of a condition, you can also pick it under Formula in the row's picker — see Conditions.

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 any element in the same top-level group: its own group, the groups above it, and the groups below any of those. An element that isn't in any group can only use formulas that aren't in a group either. Where no formula can be used, ƒ is disabled, and both it and the builder's ƒ Formula button explain: "No formulas this element can use — a formula must be ungrouped, or in the same top-level group as this element". In a condition row, the bottom of the picker also says how many formulas exist that the element can't use.

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 or version 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.