Duolith docs

Errors while checking a page

E0171 Behaviour called away from the top of a script

Message name is a behaviour, and is called only at the top of a script

Words in italics are filled in when the compiler reports it, such as the element's name or the list of known ones.

Why

A behaviour makes state, derived values and effects, and each call makes a new set of them, owned by the file that calls it (decision 0152). Called at the top of a page's, layout's or component's script, or at the top of another behaviour's body, it runs once for each screen or placed copy. Called inside a condition, a loop, a handler or a markup expression it would make new state each time that code runs, losing what the user did and leaving effects running. Naming it anywhere else, such as const make = calendar, would let it be called from there, so that is refused too.

How to fix it

Call it once at the top, such as let { month, move } = calendar({ start: value }), and use what it returns where you need it. To start again, give the behaviour a function that resets its state and call that.

In a terminal

duolith explain E0171

Mentioned in