Adds subscriber management to a game element. Applied automatically
to @plot and @quest elements via the $has_subscribers Rez stdlib mixin.
Subscribers are other game objects that receive event notifications when the
element fires lifecycle events. Subscribers are notified in descending priority
order (highest priority attribute first; default priority is 0).
Example
Subscribe an actor to a plot
const plot = $("main_quest");
const actor = $("player");
plot.subscribe(actor);
// The actor's on_plot_did_advance handler will now be called when
// the plot fires plot_did_advance.
plot.advance();
// Later, stop receiving notifications
plot.unsubscribe(actor);
Methods
# static notifySubscribers(event, paramsopt)
Fires the named event on every current subscriber, sorted by
descending priority attribute (highest first, default 0).
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
event |
string
|
The event name to fire on each subscriber |
||
params |
Object
|
<optional> |
{} | Additional parameters passed to the event handler.
A |
# static subscribe(refOrId)
Adds a game object as a subscriber. The object will receive event
notifications when HasSubscribers#notifySubscribers is called.
Throws if refOrId cannot be resolved to a known game object ID.
Parameters:
| Name | Type | Description |
|---|---|---|
refOrId |
string
|
Object
|
A game object reference or element ID to add as a subscriber |
# static unsubscribe(refOrId)
Removes a previously added subscriber. Has no effect if the object
is not currently subscribed.
Throws if refOrId cannot be resolved to a known game object ID.
Parameters:
| Name | Type | Description |
|---|---|---|
refOrId |
string
|
Object
|
A game object reference or element ID to remove |