Quick Start
In this tutorial we will create a simple action that prints the name of a behavior when it starts running.
Show Final Code
Lets start by creating a new project and running it.
📣 Our First Action
Ok, now we’re ready to create our first action. Actions are a component with associated behavior, in this case an observer that watches for the OnRun
trigger.
Now we can update the main function to create a new App
and run our first behavior.
Now lets give that a go.
But wait, we didn’t add the LogNameOnRun
component, so why did it print something out? When we call app.observe
, that creates a global listener. Sometimes that is what we want, but action observers are usually designed for a single behavior.
📋 The Action
Macro
Beet provides the Action
macro which ensures that action observers are only triggered on entities that have the associated component. Lets update our code to use the macro.
- Add the
Action
macro - Register the action’s observers with the
ActionPlugin
- Add the
LogNameOnRun
component to the entity - Run the updated code
Yaay! Now our log_name_on_run
observer will only run when it is triggered on entities with the LogNameOnRun
component.
🌲 Trees
Now we have the basic workflow down we’re ready to create our first tree.
For this we will use two actions built into Beet:
SequenceFlow
A sequence runs its children in the order they were added.EndOnRun
This action will immediately trigger anOnRunResult
which bubbles up to its parent.
Lets add the SequenceFlow
and two children.
Can you guess what the output will be?
Congratulations, you just created your first behavior!
🎸 Just for fun
An OnRun
trigger usually returns an OnRunResult
. Lets change a few lines to see that in action.
Note how the order previously reflected the order in which each behavior starts, but now reflects the order in which they end.