Formulas overview
A formula is a small calculation Stoatly runs for you. Work out a weapon's damage per second from its damage and attack speed, or the cost of an upgrade from its level. Write it once and the answer stays right whenever the inputs change. Admins and schema designers create formulas, and designers and viewers see the results.
Formulas are written against an object type, so they can read that type's fields. Project-wide calculations that don't belong to any type are global formulas.

Three ways to use a formula
| Kind | Takes parameters | Where the result goes |
|---|---|---|
| Formula field | No | A calculated value on every record of the type |
| Runtime formula | Yes | A method in your generated C# that your game calls with its own values |
| Global formula | Usually | A method on a single Globals class, with no record |
A formula with no parameters can be shown on records through a formula field. Adding a parameter makes it a runtime formula, which your game calls with values it supplies.
What a formula can use
- Fields of the object type, including inherited ones.
- Parameters, the values your code passes in.
- Other formulas on the same object type.
- Numbers and true or false values.
- Operators and functions, such as add, multiply, compare, and or not, round, floor, ceil, abs, min, max, clamp, lerp, remap, sqrt, log, exp, sign and if.
The type of the answer comes from the expression itself. The editor shows it as the formula's Returns type.
Ready to try one? Create a formula.