Give a behavior more ways in and out, and hear it as an event (#294)
game-maker / gate (push) Successful in 2m48s
game-maker / suite (push) Failing after 13m34s

A behavior run by another one had a single flow port at its Start
and at its End, so it could not branch for its caller. And it could
not be used as an event: a call needs a pulse at its flow input,
and the events of a called graph never fire. An input like
"Confirm" (Space or Enter) had to be built again in every graph.

- A declared port of a Start or an End node can be of the kind
  Flow. It sits above the values and shares their names, exec stays
  reserved. Only these two nodes declare one, a struct does not.
- Run behavior shows a flow port of the Start as a further flow
  input. A call arriving through it leaves the Start through the
  output of that name and not through exec.
- Run behavior shows a flow port of the End as a further flow
  output. The call goes on through the one the End was reached by
  last, and then through exec. exec fires always, as before.
- On behavior is a new event node without a flow input. The
  behavior it names runs at the node for as long as the behavior
  around it runs, with all of its own events and one set of
  variables per node.
- Its outputs are those of the End. It fires once the inner pulse
  is through, by the output the End was reached by last, exec only
  for End.exec. A pulse that never reaches the End is not seen.
- The value ports of the Start are its inputs, read anew for each
  inner pulse. The Start itself never fires there.
- It nests to any depth. Under a Run behavior it stays silent. A
  behavior hearing itself, however far round, is not started and
  the node says "A behavior cannot listen to itself".
- The palette offers every other behavior with an End once more as
  "On <name>". A node naming one without End says so.
- An On node removed while the game runs ends its behavior with On
  disable and On destroy. The sounds of the entity end only with
  the behavior placed on it.
- Renaming and deleting a declared port follows the edges at On
  behavior nodes as it does at Run behavior nodes.
- The flow outputs of the Start of a behavior placed on an object
  never fire, like its exec.
- The engine prompt of the benchmark names flow ports and On
  behavior.

Tests:
- Gate on melektaus-atx right before this commit: 215 files, 3319
  tests (3278 + 41), exit 0.
- e2e 19 on melektaus-atx: 39 checks (+4), all pass. e2e
  1-6,17-24,26,36,51: 628 checks, all pass.
- 19 unit tests in flow-ports.test.ts, 19 in on-behavior.test.ts
  on a real world, the rest in the node catalog.
- Four new e2e checks in module 19: a flow port declared by mouse
  at the End, On Confirm in the graph, the call leaving through the
  further output while playing, Enter and Space on a real keyboard.
- 19 unit counter-probes all fail their tests. One did not at first
  (a removed node kept its instance), a test was added. Two browser
  counter-probes fail their checks.
- One screenshot looked at: On Confirm with exec and pressed, the
  second flow pin at the calling node.
- The e2e sum of 1680 is counted (1676 + 4), the full suite and
  the smokes did not run.
- Not seen in the browser: flow inputs at the Start, nesting, the
  ring, values through On behavior, the palette entry. No test
  holds that the sounds of the entity go on when a heard behavior
  ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-10-02 19:33:34 +02:00
1 parent b5339b96c2
commit 46c620ae3b
26 files changed
+1211 -42

No files matched your search

+4 -2
View File
@@ -205,7 +205,7 @@ A variable, a struct field or a list item is one of: number, text, boolean, colo
Implement all of these. Names are the palette names.
- **Events:** `On start`, `On enable`, `On update` (outputs `dt`), `On disable`, `On destroy`, `On key down` (with optional auto-repeat: delay and interval in ms), `On key up`, `On key held`, `On timer` (interval; output `late`), `On collision enter` / `stay` / `exit` (outputs `other`, `other collider`, `collider`, and for enter/stay `normal x/y`, `impulse`, `point x/y`), `On click`, `On mouse wheel`, `On animation finished`, `On state entered`, `On state exited`. Keys ignore case.
- **Flow:** `Branch`, `Sequence` (grows an output whenever the last one is connected), `Repeat` (`index`, `body`, `done`), `For each` (`item`, `index`, a `break` input read before every round, `done`), `Run behavior`, `Start` and `End` (declare the inputs and outputs of a behavior that is called), `State branch`, `Set state`, `Set state by name`, `State transition`.
- **Flow:** `Branch`, `Sequence` (grows an output whenever the last one is connected), `Repeat` (`index`, `body`, `done`), `For each` (`item`, `index`, a `break` input read before every round, `done`), `Run behavior`, `Start` and `End` (declare the inputs and outputs of a behavior that is called, values and further flow ports alike), `State branch`, `Set state`, `Set state by name`, `State transition`.
- **Objects:** `Self`, `Owner`, `Parent`, `Object by name`, `Child by name` (nearest level first), `Objects by name`, `Children` (optionally recursive), `Children by name`, `Objects of asset`, `Name of`, `Is asset`, `Is enabled`, `Get position` (local and world).
- **Values:** `Variables`, `Properties`, the literals `Number`, `Text`, `Boolean`, `Texture`, `State machine`, `Sound`, `Scene`, `Animation`, `Asset`.
- **Math and logic:** `Add`, `Subtract`, `Multiply`, `Divide` (by 0 gives 0), `Modulo`, `Min`, `Max`, `Abs`, `Sqrt`, `Clamp`, `Floor`, `Ceil`, `Round`, `Lerp` (with ease: Linear, In, Out, In-out, or a curve asset), `Random`, `Length`, `Distance`, `Normalize`, `Compare`, `Equals`, `And`, `Or`, `Not`, `Select`, `First not empty`, `Time`. `Compare` and `Equals` treat two numbers as equal up to a relative 1e-9.
@@ -223,7 +223,9 @@ Two nodes carry most graphs and deserve care:
### 8.5 Calling a behavior
`Run behavior` runs another behavior as one step. The inputs declared on the callee's `Start` node become input ports of the call, the outputs declared on its `End` node become output ports. A call is synchronous and isolated: the callee runs with a fresh copy of its variable defaults and its own data cache, and values travel only through the ports. A variable of the callee marked **Keep** instead resumes from where the last call from the same node on the same object left it. A behavior calling itself raises an error. Double-clicking a call node opens the callee, with a breadcrumb back. Dragging a behavior asset onto a graph creates a call. Renaming or removing a declared port updates every caller.
`Run behavior` runs another behavior as one step. The inputs declared on the callee's `Start` node become input ports of the call, the outputs declared on its `End` node become output ports. A call is synchronous and isolated: the callee runs with a fresh copy of its variable defaults and its own data cache, and values travel only through the ports. A variable of the callee marked **Keep** instead resumes from where the last call from the same node on the same object left it. A behavior calling itself raises an error. Double-clicking a call node opens the callee, with a breadcrumb back. Dragging a behavior asset onto a graph creates a call. Renaming or removing a declared port updates every caller. A port declared on `Start` or `End` may be of the kind **Flow**: on `Start` it is a further flow input of the call, and a call arriving there begins at the `Start` output of that name only; on `End` it is a further flow output, and the call continues first through the one its `End` was reached by last, then through its plain `exec`, which always fires.
`On behavior` is the same behavior used as an event. The node has no flow input; the behavior it names runs at the node for as long as the surrounding behavior does, with all of its own events firing and its own variables, timers and local state machines, one set per node. Whenever one of its flows reaches its `End`, the node fires through the output named like the flow input reached last (the plain `exec` only when `End` was reached by `exec`), carrying the values `End` was handed. The value inputs of `Start` are inputs of the node, read anew for every inner flow. Behaviors may listen to each other to any depth; a behavior listening to itself, directly or through others, is reported on the node and not started again. Inside a behavior that is run as a call, `On behavior` stays silent.
### 8.6 Lifecycle and event order