Formula types
Every formula returns one type, and the editor shows it as the Returns badge. Stoatly works it out from the expression and uses it for the generated code, so you never set it yourself. These are the rules, so you can predict the badge and fix a formula whose type can't be worked out.

The types
| Type | Meaning | In code |
|---|---|---|
| Number | A decimal number | float? |
| Integer | A whole number | int? |
| Boolean | True or false | bool? |
| String | Text | string? |
| Enum | A value of a named enum | the enum's type, nullable |
| Unknown | Stoatly can't tell | not allowed, see below |
How each part gives a type
| Part | Type |
|---|---|
+, -, *, /, %, ^ | Number |
round, floor, ceil, sign | Integer |
abs | The type of its input |
min, max, clamp | Integer if every input is an integer, otherwise Number |
random, count_at_least | Integer |
sum_of, sum_highest, sum_lowest | The type of the value |
sqrt, exp, log, lerp, remap | Number |
Comparisons, and, or, not | Boolean |
if | The type of the two results. An integer and a number give Number |
| A number written in the formula | Number |
true or false | Boolean |
| A parameter | Its declared type: Number, Integer, Boolean or String |
| Another formula | The type that formula returns |
Whole numbers in random functions
The count, keep, min and max of the random functions must be whole numbers. In those places only, these count as Integer:
- A number written without a decimal part, such as
3. - A number field with the Integer only rule.
- An Integer parameter.
A plain number field gives "Count must be a whole number." (or Keep, Min or Max), and suggests turning on Integer only for that field or wrapping it in floor(). A number written as 2.5 gives the same error and suggests floor() or round(). Elsewhere in a formula, a written number is still a Number.
Fields
A field in a formula gives its own type:
| Field type | Formula type |
|---|---|
| Number | Number |
| Boolean | Boolean |
| Text | String |
| Enum | Enum |
| Date, Colour, Reference and others | Unknown |
A field of another object type reached through a reference is also Unknown.
When the type is unknown
Mixing types the rules can't combine, such as an if that returns a number in one branch and text in the other, gives Unknown. A runtime formula whose result is Unknown can't be turned into code, and Stoatly reports an error for it. Change the expression so the result has one clear type.
Formula fields
A formula field is generated as a nullable number property, so use a formula that returns a number or an integer there. If the formula uses random values, the property holds a range instead.