MCPcopy Create free account
hub / github.com/Calamari/BehaviorTree.js / run

Method run

src/BranchNode.js:14–47  ·  view source on GitHub ↗
(blackboard = null, { indexes = [], introspector, rerun, registryLookUp = (x) => x } = {})

Source from the content-addressed store, hash-verified

12 }
13
14 run(blackboard = null, { indexes = [], introspector, rerun, registryLookUp = (x) => x } = {}) {
15 if (!rerun) this.blueprint.start(blackboard)
16 let overallResult = this.START_CASE
17 let currentIndex = indexes.shift() || 0
18 while (currentIndex < this.numNodes) {
19 const node = registryLookUp(this.blueprint.nodes[currentIndex])
20 const result = node.run(blackboard, { indexes, introspector, rerun, registryLookUp })
21 if (result === RUNNING) {
22 this.wasRunning = true
23 overallResult = [currentIndex, ...indexes]
24 break
25 } else if (typeof result === 'object') {
26 // array
27 overallResult = [...indexes, currentIndex, ...result]
28 break
29 } else if (result === this.OPT_OUT_CASE) {
30 overallResult = result
31 break
32 } else {
33 this.wasRunning = false
34 rerun = false
35 ++currentIndex
36 }
37 }
38 const isRunning = overallResult === RUNNING || typeof overallResult === 'object'
39 if (!isRunning) {
40 this.blueprint.end(blackboard)
41 }
42 if (introspector) {
43 const debugResult = isRunning ? RUNNING : overallResult
44 introspector.wrapLast(Math.min(currentIndex + 1, this.numNodes), this, debugResult, blackboard)
45 }
46 return overallResult
47 }
48}

Callers

nothing calls this directly

Calls 4

registryLookUpFunction · 0.85
endMethod · 0.80
wrapLastMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected