Skip to Content
Stoatly Docs
Reference

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.

A formula whose Returns badge reads Integer, with the Reads as sentence below it.

The types

TypeMeaningIn code
NumberA decimal numberfloat?
IntegerA whole numberint?
BooleanTrue or falsebool?
StringTextstring?
EnumA value of a named enumthe enum's type, nullable
UnknownStoatly can't tellnot allowed, see below

How each part gives a type

PartType
+, -, *, /, %, ^Number
round, floor, ceil, signInteger
absThe type of its input
min, max, clampInteger if every input is an integer, otherwise Number
random, count_at_leastInteger
sum_of, sum_highest, sum_lowestThe type of the value
sqrt, exp, log, lerp, remapNumber
Comparisons, and, or, notBoolean
ifThe type of the two results. An integer and a number give Number
A number written in the formulaNumber
true or falseBoolean
A parameterIts declared type: Number, Integer, Boolean or String
Another formulaThe 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 typeFormula type
NumberNumber
BooleanBoolean
TextString
EnumEnum
Date, Colour, Reference and othersUnknown

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.

On this page