-
Notifications
You must be signed in to change notification settings - Fork 1
Publisher
Jump To | Go Back |
Arguments | Methods | Variables |
---|
Publishers are message processing backends. Methods are bound to the channels, and called with the supplied parameters when a channel is notified they belong to. These methods are called at the scope they are bound, which means they are run as if they were a part of the subscribing instance. Thus a single instance can subscribe to multiple channels, or even the same channel multiple times if desired. NOTE: Publisher makes use of dynamic resources, and so should always be destroyed when no longer needed to prevent memory leaks which will slow down and eventually crash your game.
var _achievement = new Publisher()
_publisher.subscriber_add( "kills", function( _number ) {
global.kills_progress += _number;
if ( global.kills_progress > 1000 ) {
steam_set_achievement("kills1000");
}
});
_achivement.channel_notify( "kills", 1 );
Name | Type | Purpose |
---|---|---|
channels... | string |
optional: If provided, will create channels with the given names. |
Jump To | top |
channel_notify | channel_add | channel_remove | subscriber_add | subscriber_remove | destroy | toString |
---|
Name | Type | Purpose |
---|---|---|
channel | string |
The name of the channel to notify. |
message | mixed |
The message to pass to the the subscriber methods. |
The channel, if it exists, will call all of its subscriber functions with message as an argument.
Name | Type | Purpose |
---|---|---|
channel | string |
The name of the channel to create. |
Creates a new channel if it doesn't exist, and ignores this if it does.
Name | Type | Purpose |
---|---|---|
channel | string |
The name of the channel to remove. |
Destroys a channel if it exists, and ignores this if it does not.
Returns: Subscriber
Name | Type | Purpose |
---|---|---|
channel | string |
The channel to subscribe to. |
method | func | The method that will be called when this channel is alerted. |
Adds the given method to the specified channel. If the channel doesn't exist, it will be created.
Name | Type | Purpose |
---|---|---|
channel | string |
The channel to remove the subscriber from. |
subscriber | Subscriber | The subscriber to remove from the channel. |
Removes the given subscriber from the specified channel. The Subscriber is what is returned when the channel is subscribed to. ote: It is good practice to remove a subscriber when they are destroyed. Failure to do so could cause the program to crash unexpectedly.
Name | Type | Purpose |
---|---|---|
None |
Cleans up the internal structures this Publisher can be safely garbage-collected.
Name | Type | Purpose |
---|---|---|
None |
Returns a string showing all the channels and their number of subscribers. Used for debugging purposes.
Jump To | top |
---|
Name | Type | Initial | Purpose |
---|---|---|---|
channels | undef |
ds_map_create() | No description. |
Devon Mullane 2020