Eh, a little too lazy to dig into it much now, but it's something like this.
Your behavior:
event: when x is pressed
event: when y is pressed
Another behavior:
event: when x is pressed
always: if y is pressed
How the engine processes it
init:
- Add a "when pressed" listener to x.
- Add a "when pressed" listener to y.
- Add a "when pressed" listener to x.
Game loop:
-run "update" for every active behavior in the game
- When it gets to "if <y is pressed>" it checks if the key "y" has just been pressed.
. . .
-for each key that has listeners (just two: x and y)
- if the key was pressed/released, call every listening function (x has two listeners, y has one)
I wasn't really thinking of it too much earlier, so I take back what I said. There is a slight difference to the listeners and the if condition in always. When it's a condition in always, then it's run together with all the behaviors other code. On the other hand, if it's a listener, all of the listeners are thrown into a single global registry, and they're all run one after the other whenever the keystate changes.
If you have 20 behaviors who all listen for "x", then all 20 of those listeners will be run one after the other once x is pressed.