Guarded Transitions
Guarded transitions allow you to transition to the next state only if a condition is met. Guarded transitions depend on the context properties of the state machine. Learn more about context here.
Quick start:
Definition
- Transition guards are available for
string
,bool
andfloat
types. You can define this in thetype
with either:
String
Boolean
Numeric
-
context_key
define which value inside the context to compare to. -
condition_type
define which type of comparaison you need:Equal
NotEqual
GreaterThan
GreaterThanOrEqual
LessThan
LessThanOrEqual
-
compare_to
define the value to compare against the value contained inside the context
Usage inside of players
Manual control of context variables
Currently you have to manually set the context values, later on this will be accomplished within ListenerActions
.
For example if you currently need a counter and transition if the button is pressed 3 times, you will have to manually increment the context value yourself. This is how you can accomplish this:
State machine definition:
Once we’ve created our .lottie and loaded it inside a player we need to add a click listener and set the numeric context on each click. The following code is pseudocode on how to achieve this:
The way you get a hold of the dotLottie player reference will vary depending on your platform, however the method names are the same. For setting numeric
, string
and bool
context use these methods:
tmp_set_state_machine_context(key: string, value: f32)
for thenumeric
contexttmp_set_state_machine_string_context(key: string, value: string)
for thestring
contexttmp_set_state_machine_bool_context(key: string, value: bool)
for thebool
context