GameMaker Studio 2 (2.3)
Icon

xPublisher

xDGameStudios

You must be logged in to obtain assets

Description

[INFORMATION]

This is a Pub/Sub implementation for GMS2.3+ Did you ever need to send messages between instances? Do you need your weather system to send a message to your entities saying it started raining? Do you need your player to publish actions that will be handle by another managing system? (ie.: achievements)

[QUICK GUIDE]

1) You need to instantiate a Publisher, using the following code:

publisher = new Publisher();
publisher.registerChannel("test"); // registers a communication channel

2) Subscribe to a channel within that publisher...

testCallback = function(_params) { show_debug_message(_params) }
subscription = publisher.subscribe("test", testCallback, false);

3) Finally you can publish to that channel with a custom parameter and all subscribers will receive that message

publisher.publish("test", "Say hello world!!"); 

4) When you need to remove a subscription you can rely on the weak reference system that will automatically remove subscription to dead instances/structs OR if GMS2 GC doesn't kick in just cancel the subscription manually using:

subscription.cancel();
// or
publisher.unsubscribe(subscription);

NOTE: manual subscription removal is more reliable

[USAGE]

This library provides a set of useful function that you can use to send messages through channels however you want.

publisher = new Publisher();

publisher.registerChannel(channel) // Registers a new communication channel
publisher.publish(channel, params) // Will publish a message (params) to that channel (triggers all channel subs)
subscription = publisher.subscribe(channel, callback, releaseRef) // Subscribes to a channel with a callback method
publisher.unsubscribe(subscription) // Removes a given subscription.
publisher.clearChannel(channel) // Removes all subscriptions to a channel

The subscription instance itself provides a set of utility functions that can be used to manipulate the event after it was scheduled:

subscription.cancel() // Cancels the current subscription.

[NOTES]

The demo project serves as an example for the Publisher system and all its code is inside the Demo folder of the asset pack. You don't need to include it to use the asset.

[COMPATIBILITY]

The asset is fully compatible with 2.3+ and is purely written in GML making it compatible with all exports available.

End User Licence Agreement (EULA).

Age Rating: 4+

Version

GMS2.3 - Version 1.0.0. Published May 20, 2021

Initial release

Loading, please wait

Package contents

Loading, please wait

What is the issue?

Loading, please wait