Behaviour · class

BehaviorRunner

One agent running one tree.

Explained in Agents and behaviour.

class BehaviorRunner<Context>
import { BehaviorRunner } from '@driftengine/core';

In depth

A character per agent and one tree between them: the tree is read-only after building, and everything that differs between two villagers following the same routine is here.

Constructor

new

constructor(tree: BehaviorTree)
ParameterTypeDescription
treeBehaviorTree

Properties

NameTypeDescription
treereadonlyBehaviorTree
pausedbooleanWhen true, tick does nothing and reports the last status.
More

Paused rather than not-called, so a debugger can hold one agent while the world runs — and so stepOnce has something to mean.

Accessors

NameTypeDescription
statusgetBehaviorStatus

Methods

tick

tick(context: Context): BehaviorStatus

Advance one tick, unless paused.

ParameterTypeDescription
contextContext

stepOnce

stepOnce(context: Context): BehaviorStatus

Advance one tick even while paused. What a step button is wired to.

ParameterTypeDescription
contextContext

reset

reset(): void

Forget everything: the next tick starts the routine from the beginning.

activePath

activePath(out: Uint32Array): number

The chain of nodes the last tick was inside, root first, filled into out.

ParameterTypeDescription
outUint32Array
More

This is the inspection the report asked for, and it costs nothing to keep: the chain is recorded as the tick descends, so asking for it later is a copy rather than a second walk. nameOf turns the indices into the names the tree was written with.

nameOf

nameOf(node: number): string
ParameterTypeDescription
nodenumber