Skip to reading
Visual Scripting in Depth

49. Send a custom event with useful data

Edition 0.86.4.3

0.86.4.3 edition with revised lessons, updated cross-references and new cinematic/camera-safety supplements. Earlier examples, screenshots and registry figures retain their stated edition context.

Download PDFView illustrations

Figure 32. Emit Event sends an event name and a JSON context object.

1. In the sender graph, add Emit Event.

2. Set Event Name to OnCustomEvent.

3. Set Event Context to {"kind":"workshop_ready","itemId":"brass_key_item"}.

4. In the listener, compare {"$context":"kind"} == "workshop_ready".

5. On TRUE, use Read Context to copy itemId into last_item.

6. Continue to a GUI update or other small response.

Using a kind field lets several custom messages share OnCustomEvent while keeping their meanings separate. For example, workshop_ready, door_unlocked and hint_requested can each have a distinct filter.

Code example
{
  "kind":"workshop_ready",
  "itemId":"brass_key_item",
  "sourceId":{"$this":"id"}
}

The sourceId field is optional. Use it only when the sender has a caller or an explicit source. A manually sent custom context does not automatically recreate every field of a normal object interaction.

The On Event dropdown offers known event families. For an ordinary authoring workflow, use OnCustomEvent plus your own context tag rather than inventing a listener name that the picker cannot select.

Page 53 of 93Permalink
Go to page