Context

⚠️ Context is still in early development. The current API methods that allow context modifications will be changed or removed in future releases. We plan to move most if all context modification in to the ListenerActions.

The state machine contains Context maps. The maps allow you to define custom variables that are then used for guarded transtions and in the future dynamic text inside your animations and syncing the frames to outside events like scrolling.

Quick start:

addStateMachine({
descriptor: {
...
},
states: [
...
],
transitions: [
...
],
listeners: [
...
],
context_variables: [
{
type: "Numeric",
key: "counter_0",
value: 1
},
{
type: "String",
key: "counter_1",
value: "init"
},
{
type: "Boolean",
key: "counter_2",
value: false
}
]
})

Format

"context_variables": [
{
"type": "Numeric" | "String" | "Boolean"
"key": string
"value": float | string | boolean
}
]

type?: string

Define the type of context variable.

Can be either Numeric (float), String or Boolean.


key?: string

Defines the context variables key.


value?: float | string | bool

Initial value.

Modifying context variables during runtime

Currently context variables are only used within guarded transitions and have to be manually set. Eventually this will be automatically managed with ListenerActions that will update the context variables when a gesture is caught.

You can update and modify the three types of context variables by calling the following methods on the dotLottie player :

  • tmp_set_state_machine_context(key: string, value: f32) Sets the numeric context.
  • tmp_set_state_machine_string_context(key: string, value: string) Sets the string context.
  • tmp_set_state_machine_bool_context(key: string, value: bool) Sets the boolean context.

Guarded transitions do work at the moment and will only transition if you set the correct value to the context variable and their condition guard is met.