Doodad scripts can respond to certain events using functions on the global
`Events` variable.
### Events.OnCollide( func(event) )
#### Events.OnCollide( func(event) )
OnCollide is called when another actor is colliding with your doodad's sprite
box. The function is given a CollideEvent object which has the following
@ -429,12 +532,15 @@ attributes:
has special behavior when touched (i.e. a button that presses in), you should
wait until Settled=true before running your handler for that.
### Events.OnLeave( func(event) )
#### Events.OnLeave( func(event) )
Called when an actor that _was_ colliding with your doodad is no longer
colliding (or has left your doodad's sprite box).
### Events.RunKeypress( func(event) )
The event argument is the same as OnCollide, with the Actor available
and Settled=true (others left as default zero values).
#### Events.RunKeypress( func(event) )
Handle a keypress. `event` is an `event.State` from the render engine.
@ -442,7 +548,7 @@ TODO: document that.
-----
## Pub/Sub Communication
### Pub/Sub Communication
Doodads in a level are able to send and receive messages to other doodads,
either those that they are **linked** to or those that listen on a more
@ -460,7 +566,7 @@ Doodads communicate in a "publisher/subscriber" model: one doodad publishes an
event with a name and data, and other doodads subscribe to the named event to
receive that data.
### Official, Standard Pub/Sub Messages
#### Official, Standard Pub/Sub Messages
The following message names and data types are used by the game's default
doodads. You're free to use these in your own custom doodads.
@ -473,10 +579,11 @@ their custom event names.
|------|-----------|--------------|
| power | boolean | Communicates a "powered" (true) or "not powered" state, as in a Button to an Electric Door. |
| broadcast:state-change | boolean | An "ON/OFF" button was hit and all state blocks should flip. |
| broadcast:checkpoint | string | A checkpoint flag was reached. Value is the actor ID of the checkpoint flag. |
| sticky:down | boolean | A sticky button is pressed Down. If linked to other normal buttons, it tells them to press down as well. Sends a `false` when the Sticky Button itself pops back up. |
| switch:toggle | boolean | A switch has been toggled from on to off. |
### Message.Publish(name string, data...)
#### Message.Publish(name string, data...)
Publish a named message to all of your **linked** doodads.
@ -498,7 +605,7 @@ function main() {
}
```
### Message.Subscribe(name string, function)
#### Message.Subscribe(name string, function)
Subscribe to a named message from any **linked** doodads.
@ -526,7 +633,7 @@ function main() {
}
```
### Message.Broadcast(name string, data...)
#### Message.Broadcast(name string, data...)
This publishes a named message to **every** doodad in the level, whether it
@ -20,6 +20,28 @@ Currently, the only way to _unlink_ two doodads is to delete one of them. With t
This section describes how the built-in doodads interact with one another when they're linked, and some example use cases. Custom doodads made by users should follow similar patterns; check the [PubSub event types](custom-doodads/scripts.md#official-standard-pub-sub-messages) used by built-in doodads, or invent your own custom event types!
### Start Flag
Link it with **any one doodad** and the that doodad will be the player
character for this level.
It is considered an error to link more than one doodad to the Start Flag.
It is undefined behavior which doodad "wins" in that case.
Upon level start, all actors linked to the Start Flag are destroyed.
### Anvil
If the Anvil receives **power** from any linked Button or Switch, it will teleport
back to its original starting location on the level. With this, players can make
a "Reset Button" for puzzle levels.
### Box
If the Box receives **power** from any linked Button or Switch, it will teleport
back to its original starting location on the level. With this, players can make
a "Reset Button" for puzzle levels.
### Buttons
Quick reference:
@ -81,6 +103,15 @@ The technicals:
* If the sender is saying **power** (false), the door will close.
* If the sender is a Switch, this message is ignored in favor of the toggle behavior.
### Electric Trapdoor
The Electric Trapdoor is basically a horizontal version of the
[Electric Door](#electric-door).
* Opens when it receives power from a Button, closes when power is removed.
* Always toggles state when powered from a Switch regardless of the Switch's
actual power status.
### Warp Doors
Warp Doors let the player fast travel across the map by sending them to a linked Warp Door.