Skip to content

Templates

Shaye Garg edited this page Oct 3, 2021 · 8 revisions

Templates and behavior expressions are what lets you actually do stuff with behave.

What is a template?

A template is essentially a function that can be used inside the behavior element (or inside other templates).

The template can then generate behavior expressions according to the arguments it receives.

Behavior expressions

behave has many behavior expressions:

  1. use
  2. component
  3. animation
  4. visiblity
  5. emissive
  6. interaction
  7. events
  8. update
  9. inputevent

Writing a template

A template definition has the form:

template <ident>(<ident>: <type>, <ident>: <type> = <expr>) {
    <anything_that_can_go_in_behavior>
}
// This would be:
template MyTemplate(node: str, id: num = 0) {
    // Stuff
}

anything_that_can_go_in_behavior:

  1. Any behavior expression
  2. An expression that either evaluates into a behavior expressions or none (like ifs and switches.
  3. Variable declarations.

Templates can also have default arguments.

Clone this wiki locally